Actually, the King cannot be under attack, and cannot move through a square that is attacked, or land on a square that is under attack. That leaves, for white square h1 on the king side that could be under attack, and a1 and b1, that could be under attack on a queen side castle. For black, the squares are a8, b8, and h8.
Usually, if I do it, I don't even consider if the a1, b1, or h1 is under attack, so I can't really say how common or uncommon it is, but it would be uncommon if not rare to happen before getting solid into the middle game or later in the game. The reason I don't consider it those squares are under attack, is because at that stage of the game, I'm calculating a lot of stuff, and the castle would be part of some bigger strategy where the consideration of those squares being under attack would be irrelevant.
that's not legal, is it?
I thought to castle all the squares involved had to not be under attack