Classic disk-stacking puzzle

Solve the Tower of Hanoi

Move the whole stack from the first peg to the last, one disk at a time, without ever placing a larger disk on a smaller one.

Moves 0 Optimal 15

Click a peg to pick up its top disk, then click another peg to move it.

📌

Click to move

No dragging required — click a source peg then a destination peg to move the top disk.

📊

Compare to optimal

Your move count is shown right next to the mathematically optimal number of moves.

Watch it solved

Auto-solve animates the shortest solution end to end whenever you want to see it in action.

How to play Tower of Hanoi

All disks start stacked in order of size on the first peg. The goal is to rebuild that exact stack on the last peg.

  1. Pick a source pegClick the peg holding the disk you want to move. It highlights to show it's selected.
  2. Pick a destination pegClick a different peg to move the top disk there, as long as it isn't smaller than the disk already on top.
  3. Rebuild the towerKeep moving disks one at a time until the whole stack sits on the last peg in the original order.

About the puzzle

Tower of Hanoi is a classic recursive puzzle often used to teach problem decomposition: to move n disks, you first move the top n-1 disks out of the way, move the largest disk, then move the n-1 disks back on top of it. That recursive structure is exactly why the minimum move count grows so quickly as disks are added.

Exponential growth

Each extra disk roughly doubles the minimum number of moves required, from 7 moves at 3 disks to 255 moves at 8 disks.

A recursive strategy

The optimal solution is defined recursively: solve for one fewer disk, move the biggest disk, then solve for one fewer disk again.

Only one rule to remember

A disk can never be placed on top of a smaller one — every other move is fair game.

Great for practicing planning

Because early moves constrain later ones, thinking several moves ahead pays off far more than moving disks at random.

Tower of Hanoi FAQ

Common questions about the rules, move counts and auto-solve.

What is the goal of Tower of Hanoi?

Move the entire stack of disks from the first peg to the last peg, moving only one disk at a time and never placing a larger disk on top of a smaller one.

What is the minimum number of moves?

The optimal number of moves for n disks is 2 to the power of n, minus 1. For example, 3 disks need 7 moves and 8 disks need 255 moves.

How do I move a disk?

Click the peg holding the disk you want to move, then click the peg you want to move it to. An illegal move, like placing a larger disk on a smaller one, is simply ignored.

What does auto-solve do?

Auto-solve animates the shortest possible solution move by move so you can watch the optimal strategy play out, then you can try to match it yourself.

Can I change the number of disks?

Yes. Choose anywhere from 3 to 8 disks before starting, which changes both the difficulty and the optimal move count.