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.
- All of the squares the king passes through must not be under attack
- The king and rook must be in the same team
- Both must be on the first rank (this is to prevent a king castling across the board with a pawn that promoted into a rook that hasn't moved yet)
Note that the rook can castle while under attack.
Castling with the rook closer to the king is called kingside castling/short castling, while castling with the rook closer to the queen is called queenside castling/long castling.
The algebraic term for castling kingside is 0-0, while queenside is 0-0-0. Castling is considered to be a king move.
Castling can determine future weaknesses and attacks. For example, on the right, white should not create a kingside Pawn Storm because it will severely weaken the king.
Hand castling is the act of manually moving the king and rook into the castle position. Typically, a player would hand castle when they have already moved their king or rook and are unable to castle.