1.e4 e5 2.Nf3 Nc6 3.Bc4 Bc5 4.c3 Nf6 5.d4 exd4 6.cxd4 Bb4+, and White would dearly love to tuck the king away. Look at the kingside: f1 and g1 are empty, the rook is on h1, and g1 is a square the bishop on b4 cannot reach. Short castling would answer the check perfectly. It is still illegal.
8
7
2
a
b
c
d
e
h 1 The right is postponed, not lost
The Laws phrase it as castling being prevented temporarily, and the word doing the work is temporarily. Nothing is destroyed. Block the check or capture the piece giving it, and the king has not moved, the rook has not moved, and castling is back on the menu the moment the check is gone.
That is exactly what happens in the diagram. 7.Nc3 blocks on the b4-e1 diagonal, and after 7…Nxe4 White plays 8.O-O, two moves after being in check, straight into a main line of the Giuoco Piano that has been argued about for a hundred years.
What does cost you the castle permanently is answering with the king. 7.Kf1 is perfectly legal there, and it is why this rule bites so often: when the only other replies are awkward, a check can push you into a king move you did not want, and the rook on h1 sits out the rest of the game. Before you play the king move, look twice for a block.
The two other bans people mix up
Three squares have to be clean when you castle, and every one of them belongs to the king:
- the square the king stands on (e1 or e8), which is the one this page is about
- the square the king crosses (f1, d1, f8, d8)
- the square the king lands on (g1, c1, g8, c8)
What is allowed, and surprises almost everyone: the rook can be attacked, and the rook can cross an attacked square. Castling queenside with an enemy bishop covering b1 is fine, because b1 is the rook’s business and the rule says nothing about the rook. The full set of conditions is on when you cannot castle, the crossing rule has its own page on castling through check, and the same ban seen from the castling side is on can you castle out of check.
At the board it can cost you more than the castle
Touch-move (Art. 4.3) makes you move a piece you deliberately touch, if that piece has a legal move. In the diagram your king has two, Kf1 and Ke2. So if you reach for the king meaning to castle, remember halfway that you cannot, and pull your hand back, you have already committed yourself to one of those two, and the arbiter will hold you to it. Reach for the rook first and you can lose the castle on that side altogether, which is why the king always moves first.
None of this is theory you memorise. Play through fifty castling puzzles and the illegal ones stop occurring to you.