It entirely depends on the opening. Sometimes White will castle after a mere four moves, e.g. in a Réti set-up after Nf3, g3, Bg2 castling kingside (‘short’) is already possible on the following move.
In other cases - especially against Sicilian set-ups, when White wants to castle queenside (‘long’) - this can take up to nine moves or more. In rare cases White’s even doesn’t castle at all.
As far as Black is concerned, he/she will often follow suit. In the first-mentioned Réti set-up, if Black has copied White’s moves, (s)he may safely castle short as well.
But in some Sicilians it may be wise to wait till White has made a decision whether to castle short or long.
These are very general rules.
Practice will teach you what to do.
Again, in the Sicilian openings (or the Pirc/Modern Defence) with opposite castling, you may get a mutual race between White attacking Black’s king on the kingside and Black doing likewise on the queenside with White’s king.
Like every other beginning chess player, I've heard the basic drill: "Castle early, castle often." Most of the time I do this, usually on the kingside. Sometimes, though, the "game analysis" suggests I should have continued with other developing moves on the queenside first, so my first question involves timing.
Is it best to develop on both sides before castling?
My next question is somewhat general. I've heard that castling on the kingside is more secure because the king is farther from the center of the board. But are there times when it would be better to castle queenside? Are there any advantages to it? Basically, my question is this:
How do I decide which side is best for castling?
My third question arises because of my inexperience. Time after time, I've patted myself on the back for castling, only to end up with my king trapped behind his own blockade of pawns. Sometimes I try to move a pawn early on to provide an "escape route", but doesn't that also allow an opening for my opponent? So, my third question:
What is the best way to protect my king in "the castle" without getting him trapped?
I'm sure my questions sound simplistic to more experienced players, and maybe I'll figure out the answers myself as I play more games. But could someone maybe give me some general advice... in beginner's terms?
I'll be grateful for any assistance here. I'm fascinated by this game, and I'm trying to learn all that I can. I've just got to go slow and get the basics down first.
Thanks!