Is kingside castling legal?
White to move
Solution
Kingside castling in this position: No.
Position analysis
What happens on the board after the solution.
The key idea
Kingside castling is illegal. The squares f1 and g1 are empty, but the rook on f8 attacks f1, which the king must cross. Move the black rook to a8 in this exercise position and kingside castling becomes legal.
When castling is legal
Castling rights, a clear path, and king safety.
The king’s three squares
The king may not castle out of check, through an attacked square, or onto an attacked square. The squares between the king and rook must be empty.
How castling rights are lost
A king move removes both castling rights. A rook move removes the right to castle with that rook. Returning the piece to its starting square does not restore the right.
Kingside castling
In kingside castling the king moves two squares toward its rook. The rook moves to the square the king crossed. The move is written O-O.
Sources
Check and king safety
How to identify check and test the legality of a reply.
King safety after a move
Check your own king after the move you are considering. A pawn can leave a file and expose its king to a rook check even if the king was safe before the move.
Pinned pieces
A pinned piece still attacks squares according to its movement rules. Count those attacks when testing a king move or castling.
Reading the line of check
Locate the checking piece first. If the check travels along a line, test whether it can be blocked. Then check captures and king moves.
Sources
Sources · Composed position