Chess Advanced Castling Rules
The special move of castling is tricky enough. The basics of castling include: You have to move two pieces at once, both the King and Rook, and they have to jump over each other. The King has to move exactly two squares. But that's not even the full list of obscure restrictions. There's a handful of other rules that restrict you from castling in a number of situations.
Special Advanced Castling Rules: Checks
Cannot castle into check: This rule seems quite reasonable. Your king is not allowed to move into check in other moves in the game, and this is also true for castling. So if the castling move would put your King where it would be in check, then castling is not allowed.
Cannot castle through check: This rule is quite tricky. If refers to the squares through which your king moves to castle. Not the starting square, not the final square, but the square between. If that in-between square is attacked (checked) by an enemy piece or pawn, you cannot castle. This is true even though the King couldn't actually get taken by the piece after it castled. It's just a rule that makes castling illegal. This means that you can stop someone from castling by attacking the square next to the king. It can be helpful to prevent your opponent from castling, so they have to leave their King in the middle.
Checking your opponent is OK. Yes, you can castle giving check. If at the end of the castling move, your rook is attacking your opponent's King, that's fine. In fact, it's often a good move which protects your king while attacking the enemy king. It doesn't happen often in games, but does occasionally.
Rook moving through attacked square is OK: On the Queenside, the Rook moves through the 'b' file square (b1 or b8), but the King doesn't move through that square. If that square is attacked by the enemy, castling is still allowed, it is OK. This only relates to Queenside castling; on Kingside castling the King moves through exactly the same squares as the Rook.
Special Advanced Castling Rules: Previously Moved
Cannot castle if the Rook has previously moved: If the Rook has previously moved ever in the game, you cannot castle with that Rook. You can still castle with the other Rook (if it hasn't moved). Even if the Rook moves back to its original square, you still cannot castle on that side with that Rook.