Once per game, each king can make a move known as castling. Castling consists of moving the king two squares toward a rook of the same color on the same rank, and then placing the rook on the square that the king crossed.

Castling is permissible if the following conditions are met:

Neither the king nor the rook has previously moved during the game.
There are no pieces between the king and the rook.
The king is not in check and does not pass through or land on any square attacked by an enemy piece.
Castling is still permitted if the rook is under attack, or if the rook crosses an attacked square.
Can you castle if the rook previously moved
No. 
In order to castle, the king and the rook involved in the move, must have never moved previously in the game.