Castling
A single move in which the king moves two squares toward a rook and that rook moves to the square the king crossed — legal only when neither piece has moved, the squares between them are empty, and the king is not, does not pass through, and does not end on a square attacked by an enemy piece.
Castling is the only chess move in which a player moves two of his own pieces on the same turn. It exists to let the king reach a defensive position behind a wall of pawns at the start of the game without spending the four or five king moves the manoeuvre would otherwise require, and it is essential to almost every opening played at the top level today. The mechanics are straightforward; the conditions under which it is legal are restrictive enough that players who try to castle without checking the conditions often discover, mid-move, that they cannot.
The two castlings
Castling has two forms.
Kingside (short) castling: The king moves two squares toward the kingside rook (from e1 to g1 for White, e8 to g8 for Black), and the rook jumps over the king to the square immediately on the king’s other side (f1 or f8). In notation: O-O.
Queenside (long) castling: The king moves two squares toward the queenside rook (from e1 to c1 for White, e8 to c8 for Black), and the rook jumps over the king to the square on the king’s other side (d1 or d8). In notation: O-O-O.
The king always moves two squares; the rook always ends up immediately on the king’s other side. The two forms differ only in which rook is being used.
The conditions for legality
Castling is legal only when all of the following conditions hold:
Neither the king nor the rook involved in the castling has previously moved. If the king has ever moved — even one square, even just to move out of check and back — castling is no longer permitted for the rest of the game on either side. If a particular rook has moved, castling on the side of that rook is no longer permitted, but castling on the other side may still be available if the other rook has not moved.
The squares between the king and the rook are empty. For kingside castling, the squares f1/f8 and g1/g8 must be empty. For queenside castling, the squares b1/b8, c1/c8, and d1/d8 must be empty.
The king is not currently in check. If the king is being attacked by an enemy piece, castling is not legal.
The king does not pass through a square that is attacked by an enemy piece. The king moves through one intermediate square on its two-square journey; if that intermediate square is attacked, castling is not legal even if the king’s start and end squares are both safe.
The king does not end up on a square attacked by an enemy piece. The king’s destination square must also be safe.
The most common confusion is over the third and fourth conditions: castling is forbidden if the king’s journey involves an attacked square, even if the rook’s journey crosses attacked squares. The rook, unlike the king, may pass over squares attacked by enemy pieces with no restriction; only the king is restricted.
Permissions and prohibitions for the rook
The rook may pass over squares that are under attack from enemy pieces. This is in contrast to the king. In queenside castling, the rook crosses three squares — b1/b8, c1/c8, d1/d8 — and any of those squares being under attack does not affect the legality of the move. Only the king’s journey matters.
If the queenside-castling rook itself is under attack on its starting square, the castling is still legal (the rook moves away from the attack as part of the castling move).
Practical importance
In most openings at every level of chess, both players castle within the first ten to fifteen moves. The reasons are positional: the king is safer behind a wall of three or four pawns on the wing than it is in the centre, where pawn-breaks and piece attacks are constant. The choice between kingside and queenside castling is one of the central strategic questions of the opening, and many openings (the Sicilian Najdorf, the King’s Indian Defence, the Slav) involve calculations that turn on which side each player will castle to.
Opposite-side castling — one player kingside, the other queenside — produces the sharpest middlegames in chess. Each player attacks the wing where the opponent has castled. The Sicilian Najdorf, the Yugoslav Attack against the Dragon, and the Sämisch King’s Indian are the classical opposite-side-castled openings; they are widely considered the most aggressive games chess produces.
Edge cases
Can I castle out of check? No. The king must not be in check at the start of the castling move.
Can I castle through check? No. The king cannot pass over a square that is attacked.
Can I castle into check? No. The king must not end on an attacked square.
Can I castle if my rook is being attacked? Yes. The rook’s safety is not part of the legality test; only the king matters.
Can I castle in the long form if the b-square is attacked? Yes — for queenside castling, the king’s journey is from e to c, so the b-square is not on the king’s path. The b-square’s status does not affect legality.
Can I castle if it would be the rook’s first move but the king has moved before? No. The king having moved at any time disqualifies both sides of castling permanently.
The rule has not changed in any substantive way since the modern codification of chess in the seventeenth century. It is recorded in the FIDE Laws of Chess as Article 3.8 and is, by general consensus, the most important strategic rule in the opening phase of the game.