What castling does
When you castle, the king moves two squares toward a rook, and that rook moves to the square immediately on the other side of the king. This can be done on the kingside or queenside.
The purpose is practical: your king usually becomes safer, and one rook becomes more active for the middlegame.
When castling is legal
- The king has not moved earlier in the game.
- The rook used for castling has not moved earlier in the game.
- There are no pieces between the king and that rook.
- The king is not currently in check.
- The king does not pass through check.
- The king does not land on a square under attack.
Common beginner mistake
You may castle if the rook is attacked, but you may not castle if the king is in check, crosses an attacked square, or lands in check. Castling is about the king's safety first.
Quick test
Before castling, ask: has my king moved, has this rook moved, are the squares clear, and is my king safe on every square it touches?