How to play Tower of Hanoi
- Pick the number of disks. 3 disks is a 7-move warm-up; every extra disk doubles the work, up to 255 moves for 8 disks. Each size keeps its own game and best score.
- Pick up the top disk. Tap a peg to lift its top disk (it rises above the peg), or press and drag that disk straight away.
- Drop it on another peg. Tap the peg you want, or let go of the dragged disk over it. A disk may only go on an empty peg or on a bigger disk.
- Move the whole tower to peg C. The puzzle is solved when every disk sits on the right-hand peg, biggest at the bottom. The counter shows your moves next to the minimum, 2ⁿ − 1.
- Use Undo, Hint or Solve when stuck. Undo takes back a move. Hint plays the best next move from wherever you are, and Solve plays the rest of the shortest solution so you can watch the pattern. Games with hints don’t count as a best.
Tower of Hanoi solution for 3 disks (7 moves)
Here is the shortest solution, move by move. Notice how the smallest disk moves on every other turn, and how the biggest disk moves exactly once, right in the middle.
For 4 disks, first move the top three to the middle peg (7 moves), move disk 4 to C, then move the three back on top of it (7 more): 15 in total. Every size works the same way, which is why the count doubles and adds one each time.
Minimum moves for 3 to 8 disks
| Disks | Minimum moves (2ⁿ − 1) | At 1 move per second |
|---|---|---|
| 3 | 7 | 7 s |
| 4 | 15 | 15 s |
| 5 | 31 | 31 s |
| 6 | 63 | 1 min 3 s |
| 7 | 127 | 2 min 7 s |
| 8 | 255 | 4 min 15 s |
The formula comes from the recursive idea: to move n disks you move n − 1 disks out of the way, move the biggest, and move the n − 1 back — so moves(n) = 2 × moves(n − 1) + 1, which works out to 2ⁿ − 1.
Tower of Hanoi strategy: two ways to think about it
- Think big disk first (recursion). Ask “where must the biggest disk that isn’t home yet go?” Everything above it has to be stacked on the one remaining peg first. Repeat the same question for that smaller tower. This works from any position, which is exactly how our Hint button decides.
- Follow the smallest disk (no thinking needed). Move the smallest disk every second turn, always round the pegs in the same direction; in between, make the only other legal move. With an odd number of disks the small one goes A→C→B→A…, with an even number A→B→C→A….
- Never stack two disks of the same parity. In a perfect solution an odd-numbered disk is never placed straight onto another odd one (or even onto even). If you are about to, it is usually a wasted move.
- Count to check yourself. Halfway through a perfect solve (after 2ⁿ⁻¹ − 1 moves) every disk except the biggest should be stacked on the middle peg.
Why teachers use the Tower of Hanoi
The puzzle was invented by the French mathematician Édouard Lucas and sold in 1883. It is a classic for teaching recursion in computer science, powers of two in maths, and planning ahead in psychology (the closely related Tower of London test). For children, 3 disks is a good start; once 7 moves feels easy, add a disk and talk about why the number roughly doubles.
Like it? Try more logic games that reward planning: peg solitaire (jump pegs until one is left), the 15 puzzle, the classic klotski sliding block, or our logic puzzles for kids. Chinese speakers can play the 汉诺塔 version of this page with the same saved games.