Last In, First Out
The Stack
Spells resolve in reverse — the last cast is the first to land.
Step 1 of 7
Player A casts Lightning Bolt targeting Player B (3 dmg).
Player B: 20 life
Sequence
Priority
The active player receives priority first in most steps and phases, and after a spell or ability resolves. Players then pass in turn order. Mana abilities and effects that instruct you to cast a spell have special timing rules.
LIFO Resolution
The stack is last-in, first-out. The most recently cast spell or activated ability resolves first.
Pass to Resolve
When all players pass priority in succession with no spells or abilities being added, the top of the stack resolves.
Counterspell on your spell
Counterspell goes on top, and its caster receives priority again. When priority reaches you, you may respond before it resolves. Nothing resolves until every player passes in succession.
Triggered ability
A triggered ability is put on the stack before the next player receives priority. Every player has a chance to respond before it resolves.
Two spells in a row
You can hold priority to cast another spell if its timing allows it. The second spell goes above the first. Players receive priority again between resolutions.
Reference: Official Comprehensive Rules, section 117: Timing and Priority.