Castling consists of moving the king 2 squares towards a rook, then moving the rook onto the square over which the king crossed. Castling is only permissible if all of the following conditions hold:
- The player must never have moved both the king and the rook involved in castling.
- There must be no pieces between the king and the rook.
- The king may not currently be in check, nor may the king pass through squares that are under attack by enemy pieces. As with any move, castling is illegal if it would place the king in check.
- The king and the rook must be on the same rank (to exclude castling with a promoted pawn).