When neither piece has previously moved, and the squares between the king and either rook are clear, the king moves two squares toward his rook and the rook is placed on the other side, next to the king.


Check here to know about special conditions such as not being able to castle through check, into check, or out of check http://en.wikipedia.org/wiki/Castling
how to castling in chess?