Free puzzle game and solver · Tower of Hanoi

Tower of Hanoi Play online · 3 to 8 disks · hint and solver from any position

Move the whole stack from the left peg to the right peg, one disk at a time, never putting a bigger disk on a smaller one. Hint shows the best next move from wherever you are, and Solve from here finishes it in the fewest moves.

Play the game

Updated

Play the Tower of Hanoi

Moves: 0 · Fewest possible: 15

Tap a peg to pick up its top disk, then tap the peg to put it on.

Tower of Hanoi facts at a glance

The Tower of Hanoi on this page lets you play with 3 to 8 disks, and its solver can finish any position you reach, not only the starting stack. It is free, needs no account and runs in your browser.

Source: the rules and move counts checked in this solver’s code. Updated .
Disks3 to 8, starting on peg A; the goal is peg C
Fewest moves2n − 1 for n disks: 7 for 3, 15 for 4, 31 for 5, 63 for 6, 127 for 7, 255 for 8
RulesMove one disk at a time, only the top disk of a peg, never onto a smaller disk
HintThe next move of the shortest way to finish from your current position
SolverPlays the fewest remaining moves from any legal position, and lists them
64 disks18,446,744,073,709,551,615 moves, about 585 billion years at one move per second
Price and setupFree, no account, no download; runs in your browser

How to play the Tower of Hanoi

Move the stack from peg A on the left to peg C on the right. Tap a peg to lift its top disk, then tap the peg where it should go.

  1. Pick the number of disks. Start with 3 disks (7 moves) and work up to 8 (255 moves).
  2. Lift a disk. Tap a peg; its top disk lifts up. Tap the same peg again to put it back.
  3. Drop it. Tap another peg. The disk lands if that peg is empty or its top disk is bigger.
  4. Ask for help when you need it. Hint marks the best next move from your position. Undo takes back your last move.
  5. Let the solver finish. Solve from here plays the fewest remaining moves and lists them, so you can follow along or copy them.

The Tower of Hanoi solution, step by step

With 3 disks the shortest solution has 7 moves: disk 1 from A to C, disk 2 from A to B, disk 1 from C to B, disk 3 from A to C, disk 1 from B to A, disk 2 from B to C, and disk 1 from A to C. Disk 1 is the smallest.

The same idea works for any number of disks. To move a stack of n disks, first move the top n − 1 disks out of the way to the spare peg, then move the biggest disk to the goal, then move the n − 1 disks on top of it. Each extra disk doubles the work and adds one, which is why n disks take 2n − 1 moves: 15 for 4, 31 for 5, and 255 for 8.

A trick you can do without thinking

Every other move is the smallest disk, and it always travels in the same direction round the three pegs. With an odd number of disks it goes A to C to B to A; with an even number, A to B to C to A. On the moves in between, there is only one legal move that does not touch the smallest disk, so make that one. Follow these two rules and you will finish in the fewest moves without planning ahead.

Fixing a game that went wrong

If you have made extra moves, you do not need to start over. The solver works from any legal position: it looks at the biggest disk that is not yet on peg C, clears every smaller disk onto the spare peg, moves the big disk across, and repeats. That is always the shortest way to finish from where you are, and it is what Hint and Solve from here use.

Where the puzzle comes from

The French mathematician Édouard Lucas published the Tower of Hanoi in 1883, with a legend about priests moving 64 golden disks: when they finish, the world ends. At one move per second without a mistake, 64 disks would take 18,446,744,073,709,551,615 moves, about 585 billion years.

Frequently asked questions

What is the fewest number of moves for the Tower of Hanoi?

2 to the power of the number of disks, minus 1. That is 7 moves for 3 disks, 15 for 4, 31 for 5, 63 for 6, 127 for 7 and 255 for 8.

What is the solution for 3 disks?

Disk 1 from A to C, disk 2 from A to B, disk 1 from C to B, disk 3 from A to C, disk 1 from B to A, disk 2 from B to C, disk 1 from A to C. Disk 1 is the smallest.

Can the solver finish a game I already started?

Yes. Hint and Solve from here work from any legal position, not only from the start, and always use the fewest moves left.

Does the stack have to end on the right peg?

Here the goal is peg C on the right. In the puzzle itself any peg other than the start works the same way and takes the same number of moves.

Is there an easy rule to remember?

Move the smallest disk every other turn, always in the same direction round the pegs: A to C to B for an odd number of disks, A to B to C for an even number. In between, make the only legal move that does not use the smallest disk.

Is the Tower of Hanoi game free?

Yes. It is free, with no account and no download, and it runs in your browser.

More puzzle solvers

Sorting puzzles

Grid and logic puzzles

Cards, words and colors

All tools