Tower of Hanoi Online: Free Puzzle with 3 to 8 Discs and Solver

Browser Games›Tower of Hanoi

Tower of Hanoi is a puzzle with three pegs and a stack of discs of different sizes. Move the whole stack to the gold peg on the right, one disc at a time, never putting a larger disc on a smaller one. Play with 3 to 8 discs, with hints, undo and a full solution.

How to play Tower of Hanoi

  1. Choose the number of discs at the top, from 3 to 8. They all start on the left peg, the largest at the bottom.
  2. Take the top disc of any peg and put it on another peg. Only the top disc of a peg can move.
  3. A disc may land on an empty peg or on a larger disc, never on a smaller one. If you try, the disc shakes and stays lifted.
  4. Use the middle peg as a parking place.
  5. The puzzle is solved when the whole tower stands on the gold peg on the right.

Controls on phone and desktop

  • Phone, tablet and mouse: tap or click a peg to lift its top disc, then the peg where it should go. Tap the same peg again to put the disc back. You can also drag a disc onto a peg.
  • Keyboard: keys 1, 2 and 3 are the three pegs. Press 1 and then 3 to move the top disc from left to right. Z takes back a move, H shows a hint.
  • Undo has no limit and takes the move off the counter. Hint lights up the disc to move next and marks where it goes, from any position.
  • Solve plays the shortest solution from the current position, move by move. Press it again to stop.

Minimum moves and stars

With n discs, the shortest solution has 2n − 1 moves. Each extra disc doubles the number and adds one, because the smaller tower has to be moved twice: once out of the way and once back on top.

You get three stars for the minimum, two for up to 30 percent more (20 moves with 4 discs) and one for any other solution. The clock starts with your first move, and your best is saved for each number of discs.

  • 3 discs: 7 moves
  • 4 discs: 15 moves
  • 5 discs: 31 moves
  • 6 discs: 63 moves
  • 7 discs: 127 moves
  • 8 discs: 255 moves

How to solve it: tips and patterns

  • Think in towers, not discs. To move n discs to the right, move the n − 1 smaller discs to the middle, move the largest disc to the right, then put the n − 1 discs on top of it. Each smaller tower is solved the same way.
  • The first move decides the rest. With an odd number of discs (3, 5, 7) the smallest disc goes to the gold peg first. With an even number (4, 6, 8) it goes to the middle peg.
  • The smallest disc moves every second move, always in the same direction: left, right, middle, left with an odd number of discs, and left, middle, right, left with an even number.
  • In between there is only one possible move. Leave the smallest disc alone: only one move between the other two pegs is allowed. These two rules solve any tower in the minimum number of moves.
  • Lost in the middle? Find the largest disc that is not yet on the gold peg. Every smaller disc has to gather on the third peg, the one that is neither its peg nor the gold peg.

The legend of the 64 discs

Édouard Lucas, a French mathematician, published the puzzle in 1883 with a story about a temple where priests move 64 golden discs, and the world ends when they finish. 64 discs need 264 − 1 moves, about 18.4 quintillion. At one move per second that takes around 585 billion years.

Rules used here

The tower starts on the left peg and must end on the gold peg on the right. Hints are allowed and are listed in the result. The demonstration is for learning: once it has moved a disc, the game gives no stars and saves no best until you restart. A game in progress is kept for each number of discs.

Frequently asked questions

What is the minimum number of moves in Tower of Hanoi?

With n discs it is 2 to the power of n, minus 1: 7 moves for 3 discs, 15 for 4, 31 for 5, 63 for 6, 127 for 7 and 255 for 8.

How do you solve Tower of Hanoi with 3 discs?

Call the pegs A, B and C, with the tower on A and the goal on C. The seven moves are: A to C, A to B, C to B, A to C, B to A, B to C, A to C.

Is there a trick that works for any number of discs?

Yes. Move the smallest disc every second move, always in the same direction, and in between make the only other move that is allowed.

Does the Solve button count as solving the puzzle?

No. It is a demonstration that plays the shortest way from the position on the board. A game with demonstration moves gets no stars and no best result. Hints do count.

Does it work on a phone, and is my progress saved?

Yes. Tap a peg to lift a disc and tap another to drop it. Your bests and the game in progress are saved in this browser, with no sign-up.

More games to play

All 80 browser games →

Handy free tools

More to play