Tower of Hanoi – Online Puzzle

Move the stack to the last peg one disc at a time, never putting a bigger disc on a smaller one. 3 to 8 discs, with the optimal solution.

Last updated:

Moves0
Minimum7
Best—

Tap a peg to pick up its top disc, then tap where to put it.

Tower of Hanoi puzzle

The Tower of Hanoi is a famous maths puzzle and a favourite in computer-science classes. Move all the discs from the first peg to the last — one at a time, and never a bigger disc on top of a smaller one. With 3 discs it takes just 7 moves; each extra disc doubles the challenge. Choose 3 to 8 discs, tap or drag pegs to move, compare your moves with the minimum, and press Show me to watch the perfect solution. It's a great way to learn recursion and planning.

How to play

  1. Tap a peg to lift its top disc.
  2. Tap another peg to drop it (only onto a bigger disc or an empty peg).
  3. Move the whole tower to the right-hand peg.

Example

With 3 discs: small → right, middle → centre, small → centre, large → right, small → left, middle → right, small → right. That's the minimum of 7 moves. With 8 discs the minimum is 255 moves. Like this kind of thinking? Try thesliding puzzle or Sudoku.

Rate this tool

Frequently asked questions

What are the rules of the Tower of Hanoi?
Move the whole stack of discs from the left peg to the right peg. Only one disc moves at a time, you can only take the top disc of a peg, and a disc may never sit on a smaller disc.
What is the minimum number of moves?
For n discs it’s 2ⁿ − 1: 7 moves for 3 discs, 15 for 4, 31 for 5, 63 for 6 and 127 for 7. Each extra disc doubles the work, plus one.
Is there a trick to solving it?
Yes. Move the smallest disc every other turn, always in the same direction (left-to-right-around for an odd number of discs). On the turns in between, make the only legal move that doesn’t involve the smallest disc.
Can it show me the solution?
Yes — press “Show me” to watch the optimal solution from the start.