Castling is a special one-move swap designed to protect the king and get a rook into the action. The king moves two squares left or right toward a rook, and that rook hops directly over the king to sit next to it. You can only castle if neither piece has moved before, there are no pieces between them, and the king isn’t currently in check (or moving through an attacked square). There are two variants: king-side (shorter, written O-O) and queen-side (longer, written O-O-O).
The diagram shows both at once: White’s king-side castle on the bottom (king to g1, rook hops to f1) and Black’s queen-side castle on the top (king to c8, rook hops to d8). The blue curves are the king’s path; the taller yellow curves are the rook hopping over.
For experienced players
Castling is usually played within the first 10 moves of a game. “Long-castling” (queenside) trades a slightly slower path to king safety for a more aggressive rook placement on the open d-file.
See also:How the King Moves·How the Rook Moves