Castling is a special kind of move. You can only castle one time in a game and only in certain conditions.
Castling involves a combination of a king move and a rook move. The castling only happens on the row initially occupied by the king and rooks. By castling you make two moves:
Before we get in more details there is a notion you should be familiarized with : the king's side and the queen's side. If you divide chess board into two parts you get two sides. Looking at the board from White's side the left side is the queen's side and the right side is the king's side.
As you may guess there are two ways you can castle : on the king's side(king's side castle or short castle) or on the queen's side(queens's side castle or long castle).
Look at the following boards to better understand the notion of castling.
You should keep in mind that when you castle you should always move the king first and then the rook so that your opponent doesn't claim that your intention was to move the rook (remember the rule : If you touch a piece you have to move it).
Let's take a look at the situations in which you can't perform the castle.
Look at the following game:
Black is unable to castle on either side. He can't perform the long castle because the rook at a8 was moved. He can't castle on the king's side either because the square at f8 is under the control of the white bishop from b4. White can't castle on the king's side because there is a bishop at f1. He can, however, castle on the queen's side. Although the rook at a1 is attacked by the bishop e5 that doesn't stop the castling (look at the rules above...)
But what is the purpose of castling? Why should we castle the king and not just let it as it is? The answer to that is simple. The corner of the chess board is much safer for the king than the center. While in center the enemy pieces can attack the king from all sides when castled the king greatly reduces the areas from which it can be attacked thus making life much easier for the player. In the short version that is why you should castle. You will understand more why you should castle after you will gain some experience in chess .