Castling:
How to castle. Move your King over two squares towards the Rook you intend to castle with and place that Rook on the other side of your King. "King over two, Rook to the other side."
Here the White King can castle either King side to g1 or Queen side to c1.

To castle King side White moved his King from e1 to g1 and his rook from h1 to f1.
To castle Queen side White moved his King from e1 to c1 and the Rook from a1 all the way to d1. This is called castling long because the Rook had to move three squares to complete castling.
There are 5 rules for castling.
1: The pieces between the King and Rook must not be present on their original squares.

Either side may castle.
2: The King and Rook both cannot have moved during the game prior to castling and once castled you may not castle again.

White cannot castle. His King has moved to d1..
3: The King cannot be in check.

Black cannot castle. His King is in check from the Knight on c7..
4: The King cannot move through a check

Black cannot castle. The White Bishop attacks f8 and the White Queen attacks d8.
5: The King cannot end up in check.

Black cannot castle. The White Knight attacks g8 and the White Queen attacks c8.
As I have said castling is done to protect the King. Once castled his safety depends entirely on you.

White has castled and Black has not. The White King is very safe and as long as the pawns in front of him stay put he has little to worry about. Notice Black is missing his c7 pawn. Castling Queen side could be a bit dangerous since the c file is half open and would expose the Black King after castling. On the King side he has moved his g pawn to place the Bishop on g7. This is safe since the Queens are gone and all the pawns on the King side are still close to where the King will be. Black should castle there but he can't since White's strong Bishop is attacking f8. Black will have to be creative and find a way to get the Bishop to move off the a3 to f8 diagonal or make it to the King side without the help of castling.
.