Chess castling rules and the three squares to check

Castling moves your king and a rook in a single turn. The king travels two squares toward the rook, then the rook occupies the square the king crossed. Before you castle, check the history of the two pieces, the space between them and the king’s route. We use White’s side of the board for the examples. You can follow along in Chess.
Where do the king and rook go?
| Castle | King | Rook | Squares that must be empty |
|---|---|---|---|
| Kingside | e1 to g1 | h1 to f1 | f1, g1 |
| Queenside | e1 to c1 | a1 to d1 | b1, c1, d1 |
For Black, read the same files along rank 8. The short notation is O-O for kingside and O-O-O for queenside. Start by finding the king’s destination. It travels the same distance on either side, even though the queenside rook starts farther away.
Why does an open path still fail?
Imagine a black bishop on c4 with a clear diagonal through d3 and e2 to f1. White’s king is on e1, its rook is on h1 and the spaces between them are empty. The bishop covers f1. Kingside castling would carry the king across that attacked square, so White needs a different move.
Moving either piece earlier also matters. A rook that left h1 and returned has lost its castling right. If only that rook moved, the original queenside rook can still take part as long as every other condition holds. A king that moved and returned has lost both options.
FAQ
Can I castle out of check? The king must be safe on its starting square, its crossing square and its destination. An attack on any of those three stops the castle.
Can the rook pass through an attacked square? Yes. On White’s queenside, an attack on b1 alone allows castling if b1 is empty and e1, d1 and c1 are safe. To practice another distinction that turns on whether the king is attacked, see stalemate and checkmate.