Teleport to spawn
Get back to the world spawn point or to your bed.
Commands
/spawnpoint @s Sets your spawn point to your current position
/spawnpoint @s 0 64 0 Sets your spawn point to the given coordinates
/setworldspawn Sets the world spawn to your current position
/setworldspawn 0 64 0 Sets the world spawn to the given coordinates
How it works
The spawn point is where you appear after you die or when you first join a world. The /spawnpoint command sets a player's own spawn point, while /setworldspawn changes the global spawn for the whole world. To get back to spawn quickly, use /tp @s with the spawn coordinates, or simply /kill (the drastic option: you lose your items and XP). On servers with the Essentials or CMI plugins, the /spawn command is popular: it teleports you to spawn safely. Vanilla Minecraft has no direct "go to spawn" command, so you need to know the coordinates or set a spawn point with /spawnpoint. The /gamerule keepInventory true command keeps your inventory when you die, which makes /kill a safe way to teleport to spawn. It's worth remembering your world's default spawn, which is usually close to 0, 64, 0.
Practical tips
Sleeping in a bed sets your spawn point automatically, so you don't need a command.
The /setworldspawn command affects compasses: a compass points to the world spawn.
In Java Edition, press F3 while standing at spawn to check its coordinates.
On servers, /setworldspawn requires operator (OP) permissions.