Tower of Hanoi: move the tower, one disc at a time

Move the stack to the right-hand peg without ever putting a big disc on a small one.

Loading puzzle…

Tower of Hanoi game cover

The Tower of Hanoi, online

The Tower of Hanoi is one of the most famous puzzles in mathematics: a stack of discs, three pegs, and one simple rule, never put a big disc on a small one. With three discs it is a warm-up. With eight it takes 255 perfect moves.

Play it free online with 3 to 8 discs. Your move count and time are tracked, and the page shows the minimum number of moves so you can aim for a perfect solve.

The legend of the Tower of Hanoi

The Tower of Hanoi was invented by the French mathematician Édouard Lucas in 1883. He sold it with a legend: in a temple, priests move 64 golden discs between three poles following the same rules, and when they finish, the world will end. Fortunately, moving 64 discs takes 2⁶⁴ − 1 moves, more than 18 quintillion. At one move per second, that would take about 585 billion years.

The rules

  1. Move the whole tower from the left peg to the right-hand peg.
  2. You can move only one disc at a time, taking the top disc of a peg.
  3. A disc may never sit on top of a smaller disc.

How to play here

Tap a peg to lift its top disc, then tap the peg where it goes. You can also drag discs. Hint shows the best next move from any position, and Undo takes back as many moves as you like. Choose from 3 to 8 discs.

The perfect solution

A tower of n discs needs at least 2ⁿ − 1 moves: 7 for 3 discs, 15 for 4, 31 for 5, and 255 for 8. The solution is beautifully recursive: to move a tower of n discs, first move the top n − 1 discs out of the way, move the biggest disc, then move the n − 1 discs back on top of it.

There is also a simple pattern you can follow by hand. Move the smallest disc every other turn, always in the same direction around the three pegs. On the turns in between, make the only legal move that does not use the smallest disc. With an even number of discs, move the smallest disc one way; with an odd number, the other way.

Why play the Tower of Hanoi?

It is one of the best puzzles for learning to plan ahead and break a big problem into smaller ones, which is why it is a favorite in math and computer science classes. Try to match the minimum number of moves. For more planning puzzles, try Water Sort and the sliding puzzle.

How to play Tower of Hanoi

  1. All the discs start on the left peg, largest at the bottom.
  2. Move the whole tower to the right-hand peg.
  3. You can only move the top disc of a peg, one disc at a time.
  4. A disc may never be placed on top of a smaller disc.

Tower of Hanoi tips

Know the minimum

A tower of n discs needs at least 2ⁿ − 1 moves. That's 7 moves for 3 discs, 15 for 4 and 255 for 8. Your move count shows how close you are.

Move the smallest disc every other turn

In the fastest solution, every second move uses the smallest disc, and it always travels in the same direction around the pegs.

Think recursively

To move 4 discs, first move the top 3 out of the way, move the biggest disc, then move the 3 back on top. Each smaller tower is the same puzzle again.

Frequently asked questions

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

For n discs the minimum is 2ⁿ − 1 moves. For example 3 discs need 7 moves, 5 discs need 31 and 8 discs need 255.

Why is it called the Tower of Hanoi?

The puzzle was invented by the French mathematician Édouard Lucas in 1883, who sold it with a story about a temple tower. The name stuck, though the legend is made up.

Is the Tower of Hanoi good for the brain?

It is a classic exercise in planning and working memory, and it is often used to teach recursion. Here it is simply a fun puzzle, not a medical test.

Guides for Tower of Hanoi