In castling , the king is moved two squares toward the rook , and the rook moves past the king to the square right next to where the king has moved .
Castling consists of moving the king two squares towards a rook on the player 's first rank , then moving the rook onto the square over which the king crossed . Castling can only be done if the king has never moved , the rook involved has never moved , the squares between the king and the rook involved are not occupied , the king is not in check , and the king does not cross over or end on a square in which it would be in check .