Five things have to be true at the same moment, and they split cleanly into two groups. Two of them are about the whole history of the game: break one and it is gone for good. The other three are about this exact turn, and they usually evaporate a move or two later. Beginners who lump all five together spend games thinking they can never castle again when they could have castled on the very next turn.
The list, in the order I check it at the board:
- My king has not moved in this game.
- This rook has not moved in this game.
- Every square between the king and this rook is empty. That is f1 and g1 going short, b1, c1 and d1 going long.
- My king is not in check at this moment.
- The square the king crosses and the square it lands on are not attacked by anything.
Conditions four and five are the ones FIDE writes as a single clause (Art. 3.8): castling is prevented while the square the king stands on, the square it crosses or the square it is to occupy is attacked. Three squares. For O-O they are e1, f1 and g1. For O-O-O they are e1, d1 and c1.
Two for good, three for now
Move your king to f1 to defend something and you have paid for it permanently. Same with the rook: play Rh1-e1 on move eight, put it back on h1 on move twenty, and short castling is still dead. Those two conditions have no memory of intent, only of movement, which is why the right does not come back when the king returns.
The other three are temporary. A knight sitting on f1 walks away. A bishop on b5 that hits f1 gets kicked by a2-a4 or blocked by Ng1-e2. A check gets blocked or captured, and the king is still on its original square, so you castle next move. That is the single most useful thing on this page.
The two that look like they should stop you
They do not, and both come up in real games.
8
7
2
a
e
h 1 First, the rook may be attacked. The bishop on d4 in the diagram is looking straight at a1 down the long diagonal, and 1.O-O-O is still perfectly legal. After it, the rook stands on d1 and is defended by the king on c1, so the bishop has nothing.
Second, the square the rook passes over may be attacked. Black’s rook on b8 owns the open b-file and hits b1, which the a1 rook crosses on its way to d1. Irrelevant. The king never touches b1. Play 1.O-O-O and if Black tries 1…Rb1+ then 2.Kxb1 picks the rook up for nothing.
Before you reach for the king
Run the three temporary ones in about two seconds: am I in check, are the squares between empty, is anything hitting f1 and g1 (or d1 and c1)? The permanent two you should know without looking, because you were there when the king or the rook moved.
The trap is the fifth condition, because the attacker is usually a piece you were not looking at. A bishop on a6 or b5, a knight on e3 or g3, a rook that just landed on the f-file. There is a page on exactly that, castling through check, and a set of castling puzzles where the whole point of the position is spotting whether the move is on.