A composite move of the king and one of the rooks, castling is the only rule that allows a player to move two pieces at once. It is a move which allows the king to move two squares instead of one. It also allows the involved rook to jump over the king. To castle, all of the following conditions must be true:
If you have moved your king you can’t castle, even if you move the king back to its original square.
If you have not moved your king but have moved one of the rooks, you can castle only on the side of the unmoved rook.
you can’t castle if you are in check.
you can’t castle through check. This means that you cannot castle if an opposing piece is attacking the square that the king must cross when castling.
You cannot castle into check, meaning that you cannot castle if an enemy piece is attacking the square the king will be on at the end of the castling move.
To castle, first move the king two squares toward the involved rook. Then move the involved rook to the square immediately to the opposite side of the
king. Example: to castle kingside for white, move the king from e1 to g1, then move the rook from h1 to f1. As stated above, neither piece can have moved
previously, the king cannot be in check at the time of castling, and no opposing piece can be attacking square f1 or g1. the king must cross f1 and will
finish on g1, and the king cannot walk through check nor can he end a move in check. Similarly, to castle queenside, the king moves two squares toward
the queenside rook, from e1 to c1, for the white king. The queenside rook then moves from a1 to d1. Again, no opposing piece can be attacking square
d1 or c1, since the king must cross d1 and finish on c1 in order to castle. It does not matter, however, if an opposing piece is attacking square b1,
since only the rook, and not the king, must cross this square. It doesn’t matter if a rook crosses this square, because a rook may go through check. Nor does it matter if an enemy piece is attacking the rook at the time of castling.
It is only attack on the king that limits whether a player can castle or not.