Most castling arguments at the board come down to three questions, asked in order: has the king already moved, has that rook already moved, and is the king's path clear of pieces and attacked squares? FIDE Laws 3.8.2.1–3.8.2.2 settle every case.
Have the king or that rook already moved?
Castling rights are permanent. Once the king has moved — even if it returns to its starting square — it can never castle again in that game. The same holds per rook: if the h1 rook has moved, kingside castling is gone, but queenside castling with the a1 rook can still be legal. The scoresheet decides a dispute, because the moves tell you which rights were lost.
What can the king see?
The king cannot castle out of check, through an attacked square, or onto an attacked square. Those blocks are temporary: when the attacker moves away, castling becomes legal again.
The rook's safety never enters it. An attacked rook does not prevent castling by itself — only the king's starting, crossing and destination squares count.
A blocked path is temporary too
Any piece standing between the king and the rook prevents castling — but only while it stands there. Clear the square and the move returns.
The full reference page carries the official wording, the conditions with diagrams, and the US Chess difference; the scoresheet rule is where a lost right gets written down.