How to Master Tower of Hanoi
TLDR: Tower of Hanoi is solved by one recursive rule: to move n disks to the target peg, first move n-1 disks to the middle peg, then move the largest disk to the target, then move n-1 disks on top. Apply this rule at every level and you always reach the minimum move count. The minimum is always one less than a power of two: 3 disks needs 7 moves, 4 disks needs 15, 5 needs 31, 6 needs 63, 7 needs 127.
What the Game Is
Tower of Hanoi starts with a stack of disks on the leftmost peg, largest at the bottom, smallest at the top. Your goal: move the entire stack to the rightmost peg, obeying two rules. Move one disk at a time. Never place a larger disk on top of a smaller one.
That is it. No timers, no randomness, no hidden information. Just logic and a move budget.
PlayMemorize scales from 3 disks to 7 disks. The move budget starts above the optimal minimum so beginners can still win while learning the pattern; as your level rises, the budget tightens toward the mathematical minimum.
The minimum move counts: 3 disks = 7 moves, 4 disks = 15 moves, 5 disks = 31 moves, 6 disks = 63 moves, 7 disks = 127 moves. Each level requires roughly twice the moves of the level below, plus one. If you exceed the move budget, the round ends as a loss.
The Recursive Algorithm
Everything in Tower of Hanoi follows from one pattern, applied repeatedly at every scale:
To move n disks from peg A to peg C, using peg B as temporary storage:
- Move n-1 disks from A to B (using C as temporary)
- Move the largest disk from A to C
- Move n-1 disks from B to C (using A as temporary)
That is the complete algorithm. At every level of the puzzle, you are executing this same three-step structure. The brilliance is that steps 1 and 3 are themselves smaller instances of the same problem, solved by the same rule.
Let us trace through 3 disks to make this concrete. Goal: move all three from peg 1 to peg 3.
- Step 1 (move 2 disks from peg 1 to peg 2): move disk 1 to peg 3, move disk 2 to peg 2, move disk 1 to peg 2.
- Step 2 (move disk 3 from peg 1 to peg 3): one move.
- Step 3 (move 2 disks from peg 2 to peg 3): move disk 1 to peg 1, move disk 2 to peg 3, move disk 1 to peg 3.
Total: 7 moves. Optimal.
Three-Phase Thinking. Before touching any disk, name the three phases aloud: “Clear n-1 disks to the middle; move the biggest to the target; rebuild n-1 disks on top.” At every recursion level, you are repeating this same structure with one fewer disk. You are not memorizing a move sequence - you are executing a fractal pattern.
Tip: Before making any move, ask: “What is the largest disk I need to move right now?” Everything you do until you move that disk is preparation. Keeping this framing prevents aimless moves and keeps you on the optimal path.
Why the Move Count Is Fixed
The minimum move count follows directly from the algorithm. Solving n disks requires solving n-1 disks twice (steps 1 and 3) plus one move of the largest disk (step 2). So the total T(n) = 2 times T(n-1) plus 1. With T(1) = 1, this expands to: 1, 3, 7, 15, 31, 63, 127 for disk counts 1 through 7.
Each number is one less than a power of two. Three disks: 8 minus 1 = 7. Four disks: 16 minus 1 = 15. Five disks: 32 minus 1 = 31. Six disks: 64 minus 1 = 63. Seven disks: 128 minus 1 = 127.
This is not a coincidence - it is the direct consequence of solving n-1 disks twice each time you solve n disks. Once you understand this, you stop viewing Hanoi as a puzzle to guess your way through and start viewing it as an algorithm to execute.
Tactics by Difficulty
3 to 4 disks (learning): At this level, the move budget is comfortable. Focus on naming each disk mentally - “small,” “medium,” “large” - so you never confuse which disk you are targeting. Trace through the three phases before touching anything. After each game, explain the phases aloud: “I cleared two disks to the middle, moved the big one, rebuilt on top.”
Tip: The largest disk should move exactly once per full solution. If you find yourself wanting to move it again, you have broken the algorithm structure. The largest disk’s single move is a milestone - everything before it is clearing the path; everything after is stacking on top.
5 to 6 disks (intermediate): The move budget tightens. Every wandering move costs you. Apply the recursive algorithm strictly at each level. When you recurse down from n to n-1 disks, your mental focus should shift: you are now solving a smaller Hanoi puzzle with a different set of “source,” “target,” and “auxiliary” pegs. Track which role each peg plays at each recursion level.
The Auxiliary Peg Swap. At each recursion level, one peg is the source, one is the target, and one is auxiliary. These roles rotate as you recurse. When moving n-1 disks from peg 1 to peg 2, peg 3 is auxiliary. When then moving n-2 disks from peg 1 to peg 3, peg 2 is auxiliary. Track this swap consciously - it is the most common source of confusion at 5 and 6 disks.
7 disks (challenge): With 127 minimum moves and a tight budget, you cannot think move by move. Think phase by phase. Before starting, map the top-level structure: move 6 disks to the middle (63 moves), move the largest disk to the right (1 move), move 6 disks to the right (63 moves). Then subdivide each 6-disk phase the same way. This top-down planning reduces cognitive load and prevents the error of losing track of which phase you are in.
Watch out: At 7 disks, trying to memorize the sequence move by move is unreliable and unnecessary. Trust the algorithm. When you apply the recursive rule at every branching point, the correct move is always determined. Doubt and second-guessing are how you burn moves and exhaust the budget.
Common Mistakes
Treating it like a trial-and-error puzzle. Random moves occasionally look productive but compound into dead ends. Hanoi is an algorithm, not a puzzle to crack by experimentation. Remove randomness from your thinking entirely.
Losing track of peg roles. On three identical pegs, “source,” “target,” and “auxiliary” can blur together, especially at higher disk counts. Before starting, label the pegs explicitly in your mind: LEFT = start, CENTER = middle, RIGHT = target. Use these labels consistently across every recursion level.
Moving the largest disk more than once. At the top level of recursion, the largest disk moves exactly once. If you feel the urge to move it again, stop - the algorithm structure has broken down. Return to the three-phase framing and identify where you went off-track.
The Largest Disk Checkpoint. At each level of recursion, the n-th disk should move exactly once. After completing the first sub-phase (moving n-1 disks to the auxiliary peg), the n-th disk should be free and unmoved. After step 2, it should be on the target peg. If it is not, you have deviated from the algorithm.
Running out of moves. This only happens when you are not following the algorithm, or when you have made and then mentally “undone” moves (changed your mind mid-execution and tried a different path). Commit to the algorithm. It is optimal - there is no better path.
Watch out: Once you have decided on a move using the recursive algorithm, commit. Questioning it mid-execution leads to wasted moves. The algorithm guarantees optimality - trust it and execute without hesitation.
A Practice Plan
Week 1 - Algorithm internalization (3 disks). Play 3-disk games daily. After each game, describe the three phases aloud. Repeat until the pattern is so familiar that you can narrate the entire solution before making the first move.
Week 2 - Scaling (4 to 5 disks). Move to 4-disk games. The recursion now goes two levels deep. After each game, trace the structure: “I recursed to 3, moved the large disk, recursed again.” Play three to four games at 4 disks, then move to 5.
Week 3 - Pressure (6 disks). At 6 disks, the move budget becomes the binding constraint. Play with the algorithm as your only guide. Aim to complete two 6-disk games within five moves of the minimum (63 moves). Track your move count and watch it fall toward 63 over the week.
Week 4 - Mastery (7 disks). Attempt 7-disk puzzles. Apply top-down phase planning before touching any disk. Three consecutive wins at 7 disks with a move count close to 127 signals genuine mastery.
Tip: Keep a log of your move counts per disk level. Watching your count fall toward the minimum over sessions is the clearest external signal that the recursive pattern is internalizing. Move counts above 130 for 7 disks mean wandering moves are still appearing; under 135 with consistency means the structure is solid.
Tower of Hanoi is one of the few games where mastery is both absolute and measurable. Either you know the recursive algorithm and execute it, or you do not. Once you do, every difficulty level yields to the same logic. Slow down, name your phases, trust the algorithm, and the solution is always there.
Tower of Hanoi
Move all disks from the first peg to the third using the minimum number of moves. Classic recursive puzzle, 3 to 7 disks
Play nowWorks on any device.