When a spell is cast, its targets are chosen and locked in. Before that spell resolves, if every single one of its targets has become illegal — meaning each target no longer exists, is now protected, or otherwise can't be targeted — the spell is countered by the game rules themselves, not by any player or effect. This is covered by CR 608.2b.
A target becomes illegal if it has left the battlefield, gained hexproof or shroud, or is otherwise no longer a valid target for the spell. It's important to note that this only applies when all targets are illegal. If at least one target is still legal, the spell resolves normally and simply ignores the illegal targets (CR 608.2c).
When the spell is countered this way, it goes to its owner's graveyard (for instants and sorceries). No effects written on it take place — it simply fizzles. This is commonly called 'fizzling' by players.
Example: You cast Lightning Bolt targeting your opponent's 1/1 creature. In response, your opponent casts Giant Growth on that creature, then sacrifices it to an Altar. When Lightning Bolt tries to resolve, its only target is gone (illegal). The Bolt is countered by the rules and goes to your graveyard without dealing any damage.
This rule applies equally to abilities on the stack (CR 608.2b), not just spells. Note that spells with no targets at all are never subject to this rule — they always resolve normally regardless of what happens to the board state.
Unofficial fan resource — not affiliated with or endorsed by Wizards of the Coast. Answers are AI-generated estimates grounded in the Comprehensive Rules and are not a substitute for an official judge. Verify anything match-critical.