Here is a standard Najdorf Sicilian, and White’s ninth move is the whole point of the set-up: 9.O-O-O. The king travels e1 to c1, the rook jumps from a1 to d1, and it lands right behind the queen on d2, with the pair of them aimed at the pawn on d6.
8
7
2
a
e
f
h 1 Where everything lands
Long castling is the same idea as short, one square further along.
White: king e1 to c1, rook a1 to d1. Black: king e8 to c8, rook a8 to d8. The king moves two squares, as it always does when castling. The rook moves three, which is why the notation carries a third O.
The square b1 stays empty, and that is the visible difference from short castling. After O-O the king is snug on g1 with the rook next door on f1 and no gap. After O-O-O there is a hole at b1, the king is on c1 rather than in the corner, and the pawn on a2 has nobody looking after it.
The extra square, and the move that fixes it
Three squares have to be cleared before you can castle long, not two. The knight on b1, the bishop on c1 and the queen on d1 all have to find homes first, and that is three tempi of preparation. In the diagram above it took White until move nine, and even that is quick, because the English Attack set-up with Be3 and Qd2 clears two of them in one plan.
Once you are there, the standard follow-up is Kb1. It takes the king off the c-file, where a black rook will eventually arrive, off the c1-h6 diagonal, where a black bishop likes to sit, and it defends the a2 pawn into the bargain. Not urgent, but on the list of quiet moves to play when nothing else is pressing.
Also check the safety squares before you commit. Going long, the king stands on e1, crosses d1 and lands on c1, and all three must be free of attack. The square b1 does not count, even though the rook flies over it, so an enemy rook on the b-file is not your problem. That distinction is the subject of castling through check.
When long is the right choice
Castle queenside when your rook wants the d-file and your attack wants the kingside pawns. Those two things usually arrive together: with the king on c1 you are free to throw g2-g4 and h2-h4 forward without exposing anything, because the king is nowhere near them.
The price is that the king is a file closer to the centre and the queenside pawns are harder to keep tidy. If your opponent castles short, they will be pushing pawns at you from a5, b5 and c5 while you push at them, and the race is on. That is opposite-side castling, and it is covered in short against long. For a feel for how those races go, work through some queenside attack puzzles, where the target is nearly always a king on c1 or c8.