The only move in chess that moves two pieces at once, and the four conditions it needs.
Castling is the only move in chess that moves two pieces at once. The king moves two squares toward one of its rooks, and that rook jumps over the king to the square immediately on the other side. It is legal only if neither the king nor that rook has moved before, the squares between them are empty, and the king is not in check and does not pass through or land on a square attacked by an enemy piece.
Castling is legal only when all four hold. The first two are about history, the last two about the current position.
Kingside castling, written O-O and also called short castling, moves the king from e1 to g1 and the rook from h1 to f1. For Black the same move runs e8 to g8 and h8 to f8.
Queenside castling, written O-O-O and also called long castling, moves the king from e1 to c1 and the rook from a1 to d1. For Black that is e8 to c8 and a8 to d8. It requires one more empty square than kingside, because the b1 square must also be clear.
A king that has moved and returned to e1 has still moved, and can never castle again. The right is lost permanently, not just for that turn.
You may castle while the rook is attacked, and when castling queenside the rook may legally pass through an attacked square. The restriction on passing through attacked squares applies only to the king.
Being in check does not cost you the right to castle later. It only prevents castling while the check stands. Block or capture the checking piece without moving the king, and you may still castle afterwards.
Know the rules and want to see where your games actually go wrong? Paste any game into the free analysis board for a move-by-move review, or explore how games begin in the opening explorer.