To castle, the king is moved two spaces towards a rook. The rook is then placed on the space next to the king, on the opposite side, as if jumping over the king.
Castling can only occur when the following conditions are met:
- There must not be any pieces between the king and the rook.
- The king and the rook must not have moved earlier in the game (even if they return to their original squares).
- The king must not be in check.
- The move must not put the king in check.
- The square the king passes through must not be under attack
It is a common misconception that due to the last rule, castling cannot occur if the rook is threatened, which is false.
Castling with the rook closer to the king is called kingside castling, while castling with the rook closer to the queen is called queenside castling.
The algebraic term for castling kingside is 0-0, while queenside is 0-0-0.