Tower of Hanoi · Guide

Tower of Hanoi Strategy: Solve It in 2^n-1 Moves (2026)

slug: tower-of-hanoi-beginner-tips · Last verified 2026-10-14

Try it yourself — play Tower of Hanoi now

Free in your browser, no download or sign-up.

Play Tower of Hanoi

Last updated: October 17, 2026 · Tested on Playnesta's Tower of Hanoi build (public-domain puzzle by Édouard Lucas, 1883; rules module, shell, stylesheet, bridge and touch shim are Playnesta-original, MIT; GUI layout inspired by AJLoveChina/Hanoi @ 917b8d6, MIT, mechanism reference only) · 3 pegs · 3 to 8 disks, default 4 · optimum 2^n − 1 moves (3 disks → 7, 4 → 15, 5 → 31, 6 → 63, 7 → 127, 8 → 255)
Method: every number below is a constant in this site's shipped rules module js/hanoi.js (Playnesta-original, MIT), read and verified this session — not quoted from a third party. The puzzle is fully deterministic, so ?disks=5 reproduces the exact same starting tower for everyone, and there is no upstream build to observe. Verified constants: 3 pegs (peg 0 starts with every disk, biggest at the bottom and smallest on top; pegs 1 and 2 start empty); disk count 3 to 8, default 4; the optimum is 2^n − 1 moves; a move is legal only when the destination peg is empty or its top disk is bigger than the disk being moved, and an illegal drop (a bigger disk landing on a smaller one) is rejected instantly and changes nothing; the win fires only when a full tower lands on a peg other than the start; Undo steps back one move at a time and clears the win state; the move counter tracks against the optimum and upgrades to Perfect! when you solve it in the fewest. Controls: drag a disk to another peg, or tap a peg to lift its top disk and tap another to drop; the disk-count menu (3 to 8), Undo, Rules and New game buttons; a Solved! banner with Play again when you finish. There is no timer, so play at your own pace. The rules below are strategy — the game page already covers how to operate the board; this is how to solve it in the fewest moves.

1. The whole game is one number: 2^n − 1

For n disks the fewest moves possible is 2^n − 1, and this build shows it and grades you against it. Three disks take 7, four take 15, five take 31, six take 63, seven take 127, eight take 255. That is not a target someone picked — it is the mathematical floor, and no human can do better.

Most people who "solve" Tower of Hanoi do it in two or three times the optimum, because they move disks opportunistically and only notice the wasted moves at the end. This build's counter and the Perfect! banner exist to make that waste visible: it only upgrades to Perfect! when your move count equals 2^n − 1 on a win. Until you have seen that banner, you have not actually solved the puzzle — you have only finished it. So the first goal is not "move the tower"; it is "move the tower in 2^n − 1 moves", and everything below is how.

2. The recursive recipe that hits the floor

The optimal solution has a recursive shape, and once you see it the puzzle stops being a search and becomes a checklist. To move a tower of n disks from peg A to peg C, using peg B as spare:

  1. Move the top n − 1 disks from A to B (using C as spare).
  2. Move the largest disk from A to C.
  3. Move the n − 1 tower from B to C (using A as spare).

That is the whole algorithm. Step 2 is the only move of the largest disk; steps 1 and 3 are the same problem one size smaller. Because the largest disk can only move when nothing sits on top of it and the destination is empty, you are forced to clear it first — and clearing it means solving the smaller tower, which is forced to clear its largest disk, and so on down to a single disk.

The practical takeaway: the biggest disk moves exactly once, and only at the midpoint of the solution. If your biggest disk has moved more than once, you are not on the optimal path — you have buried it again and will have to re-clear it. Watch for that: a session where the bottom disk keeps getting re-lifted is a session that will end well over 2^n − 1.

3. The three mistakes that cost you moves

Moving the biggest disk too early. You cannot move it until its peg holds only it, so every move you make before the n − 1 tower is fully parked on the spare peg is a move that delays the one move that matters. Beginners often shuffle the top disks "to get started" and only then realise the bottom disk is still pinned.

Treating the empty peg as decoration. The empty peg is not a spare you use occasionally — it is the staging ground that makes the recursion possible. In a three-peg game, at any moment one peg holds the tower you are building, one holds the tower you are dismantling, and the third is free. If you are not consciously using all three roles, you are doing extra work to route around the one you ignored.

Playing greedy. The legal move that looks best right now is rarely the move the recursion wants next. "Move the smallest disk" feels productive because it is always legal, but the optimal sequence alternates small and large disks in a fixed pattern (for an odd disk count the smallest disk cycles A → C → B → A; for an even count it cycles A → B → C → A). If you stop thinking and just keep moving the smallest legal disk, you will finish — but not in 2^n − 1.

4. Climb the disk ladder, and know when to stop

The difficulty is not linear; it is exponential, and the move counts make that honest:

  • 3 disks / 7 moves — learn the recursion here. You can hold the whole solution in your head.
  • 4 disks / 15 moves — the first size where you must trust the recipe instead of improvising.
  • 5 disks / 31 moves — a real puzzle; one mistake and you are 10 moves over.
  • 6 disks / 63 moves — a sitting; plan to finish in one go or you will lose the thread.
  • 7 disks / 127 moves — a project; use Undo deliberately.
  • 8 disks / 255 moves — a marathon; the game allows it, but most sessions should live at 4 to 6.

The honest training path is 3 → 4 → 5, and only then 6. Jumping to 8 to "see the big one" teaches you nothing, because 255 moves of improvisation is just fatigue. The disk-count menu (3 to 8) and the ?disks=n URL parameter both let you pin a size, so fix a size for a week and chase the Perfect! banner on it before moving up.

5. Use Undo as a teacher, not a crutch

Undo steps back one move at a time and clears the win state, so it is the cleanest way to learn the recursion: play until you are unsure, undo to the last position you understood, and re-derive the next move from the recipe instead of guessing. Because the game has no timer, there is no penalty for stopping to think — the only thing being measured is the move count.

Two habits that help: replay the same seed with ?disks=4 (or any seed) until you can hit Perfect! twice in a row, and name out loud which disk you are about to move and why before you move it. If you cannot say which disk and why, you are guessing, and guessing is what pushes the count over 2^n − 1. The game also re-deals the same tower for a given ?disks= value, so you can drill one position instead of restarting from a fresh random deal each time.

FAQ

How is this different from the rules on the game page?

The game page explains how the board works — three pegs, top disk only, bigger may never cover smaller, drag or tap, the move counter against the optimum, Undo, 3 to 8 disks, no timer. This guide assumes you know that and plays the layer above it: the 2^n − 1 floor, the recursive recipe, the three mistakes, the disk ladder, and how to drill. Read the rules first, then chase the Perfect! banner.

Is 2^n − 1 really the fewest possible?

Yes. The largest disk must move at least once, and to move it the n − 1 disks above it must all be off its peg and out of the way; by induction that takes at least 2^(n−1) − 1 moves before and 2^(n−1) − 1 moves after, plus the one move of the largest disk. Three pegs is the minimum that makes the problem non-trivial, and with three pegs the floor is exactly 2^n − 1. Four-peg variants (Reve's puzzle) have a lower floor, but this game is three pegs.

Why does the banner say "Perfect!" only sometimes?

Because "Perfect!" is reserved for solving in exactly 2^n − 1 moves. Solving in more moves still wins — the Solved! banner fires and the move count is shown against the optimum — but Perfect! only upgrades when your count equals the floor. If you have never seen it, your move count is above the floor; the counter shows you by how much.

Can every deal be solved?

Yes. The starting position is always a full tower on one peg, and the recursive recipe solves it for any n from 3 to 8. There is no shuffle and no dead end — an illegal move is simply rejected and changes nothing, so you cannot paint yourself into a corner. You can always undo back to a known good state.

Which disk count should I train on?

Start at 3 until you can hit Perfect! twice in a row, then 4, then 5. Most players plateau at 5 disks (31 moves) and that is a fine place to live — 6 and above are for when you want a longer session, not for learning. Avoid 8 for training; 255 moves of improvisation is fatigue, not practice.

Where can I play it?

Right on this site's tower-of-hanoi page. The puzzle is a public-domain mathematical problem published by Édouard Lucas in 1883, so there are no byte-reused upstream files; the rules module, the page shell, the stylesheet, the analytics bridge and the touch shim are all Playnesta-original and MIT. The GUI layout is inspired by AJLoveChina/Hanoi @ 917b8d6 (MIT), which was read as a mechanism reference only and is not redistributed here. Playnesta Games is the developer and publisher of this specific web implementation.

More games to play

More free browser games on Playnesta — pick your next round.