You cannot castle:
1. If the king has already moved.
2. If your king is in check.
3. If a square which the king (but not the rook) must pass through when castling is attacked.