When it comes to castling in chess, we are usually taught to castle early, after developing some of the minor pieces.
The idea is that it can be dangerous to leave your king stuck in the middle of the back row where he may be exposed to an early attack. Generally speaking, it is more secure to get your king off to one side of the board, behind a barrier of pawns, and perhaps a knight, a rook and/or a bishop.
In the diagram both White and Black have castled early. White’s king is defended by three pawns, a knight and a rook. Black’s king is even more securely defended by three pawns, a rook, knight and bishop.
Quite often, however, other concerns cause one or both players to delay castling, or not to castle at all. In a situation where you have castled and your opponent has not, Jeremy Silman offers a “basic thesis” for you to follow, which is,