Updated:

The basic form

/gamemode creative
/gamemode survival
/gamemode adventure
/gamemode spectator

Without a target, the command changes your own mode. Add a name or selector to change someone else: /gamemode creative Steve or /gamemode survival @a.

The four modes

ModeWriteWhat it is
SurvivalsurvivalHealth and hunger; gather materials to progress.
CreativecreativeUnlimited blocks, flying, no normal damage.
AdventureadventureCannot freely break or place blocks; for maps.
SpectatorspectatorFly through blocks and watch; cannot touch anything.

Java vs Bedrock

Java 1.13 and later accept only the names. /gamemode 1 or /gamemode c are errors; they are Java 1.12 syntax from old tutorials. Bedrock accepts names, numbers (0 survival, 1 creative, 2 adventure) and letters (s, c, a):

/gamemode 1
/gamemode c @p
/gamemode s @a

Those three lines are Bedrock only. Spectator is a newer addition on Bedrock, so older Bedrock versions do not offer it.

Keyboard shortcuts (Java)

Hold F3 and press F4 to open the game mode switcher (1.16+); press F4 again to cycle and release F3 to choose. F3+N toggles between Spectator and your previous mode. Both need cheats or operator permission.

Mode for new players

/defaultgamemode survival

This sets the mode for players joining for the first time; existing players keep theirs. On servers, gamemode and force-gamemode in server.properties also matter.

Adventure maps (Java)

/gamemode adventure @a[gamemode=!creative]

This puts every player except the map makers in Creative into Adventure. To allow breaking specific blocks in Adventure on 1.20.5+, give tools the can_break component.

Common problems

Check your command

The Command Error Doctor checks common syntax mistakes in your browser.