A king left in the centre gets into danger when the centre opens. So castle to make your king safe as soon as your pieces are developed.
White's knight and bishop are developed; f1 and g1 are empty. Castle kingside.
After castling, don't move the pawns in front of your king without a reason; they are its shield. Weakening the shield gives your opponent chances to attack.
White has castled; now it's your turn. Black has developed the knight and bishop too: castle short.
Sometimes castling long is better: White's b1, c1 and d1 squares are empty. Castle long; the king goes to c1 and the rook to d1, where it works in the centre at once.