How to play the Tower of Hanoi
The Tower of Hanoi is a classic one-player puzzle made of three pegs and a set of disks of different sizes. At the start, all the disks are stacked on the left peg, largest at the bottom and smallest at the top, like a cone. Your goal is to rebuild that tower on the right peg by moving one disk at a time, without ever placing a larger disk on a smaller one. There are only two rules, yet the number of moves grows so quickly as you add disks that the puzzle has fascinated players, teachers and computer scientists for well over a century.
This online version lets you play with 3 to 8 disks, counts your moves against the minimum, times your solve, and can show you a hint for the next move or play the whole solution for you.
The start and the goal

Every game begins with the complete tower on peg 1, the leftmost peg. You win when the whole tower stands on the rightmost peg, labeled Goal, in exactly the same order. The middle peg is a spare: you can use it as often as you like to park disks along the way.
Tower of Hanoi rules

The official rules fit in two lines:
- Move only one disk at a time. You may only move the top disk of any peg. You can’t pull a disk out from the middle of a stack.
- Never put a larger disk on a smaller one. A disk may go on an empty peg or on top of a larger disk.
If you try an illegal move in this game, the disk gives a little shake and a message explains why (for example, “A larger disk can’t go on top of a smaller one”). Illegal attempts don’t count as moves, so feel free to experiment.
How to move the disks on screen

Click or tap a peg and its top disk lifts up. Then click or tap the peg where you want to put it, and the disk slides across and drops into place. Pegs where the lifted disk is allowed are outlined with a dashed frame. Changed your mind? Tap the same peg again to put the disk back. You can also grab a disk with your finger or mouse and drag it to another peg. On a keyboard, press 1, 2 and 3 to choose pegs (and 4 when you play with four pegs).
The bar above the board shows your move count, the minimum for your number of disks, and a timer. The timer starts with your first move, so you can think as long as you like before you begin. Undo takes back your last move whenever you need it.
Minimum number of moves: the 2n − 1 formula
You can choose from 3 to 8 disks. For every number of disks there is a minimum number of moves that can’t be beaten, and it roughly doubles each time you add a disk.
| Disks | Minimum moves (3 pegs) | Good for |
|---|---|---|
| 3 | 7 | Your first game |
| 4 | 15 | Learning the idea |
| 5 | 31 | Easy once you see the pattern |
| 6 | 63 | Needs concentration |
| 7 | 127 | Find your rhythm |
| 8 | 255 | A real challenge |
With n disks the minimum is 2n − 1 moves: multiply 2 by itself once for each disk, then subtract 1. Three disks take 2 × 2 × 2 − 1 = 7 moves and four disks take 2 × 2 × 2 × 2 − 1 = 15. If you finish in exactly the minimum, the game says “Solved in the minimum moves!” and records it.
Tower of Hanoi variations

Choose Custom in the settings to play two well-known variations of the puzzle.
| Rule | What changes | 4 disks |
|---|---|---|
| Standard (3 pegs) | A disk may move to any peg | 15 |
| 4 pegs | One more spare peg; move the tower to the 4th peg | 9 |
| Adjacent only | A disk may only move to a neighboring peg, so it has to pass the middle peg | 80 |
With four pegs the extra parking space cuts the number of moves dramatically: 5 moves for 3 disks, 13 for 5 disks and only 33 for 8 disks. The adjacent-only rule does the opposite. Its minimum is 3n − 1, so even 3 disks take 26 moves and 6 disks take 728, which is why this variant stops at six disks.
Tower of Hanoi solution and strategy
1. Learn the 7-move solution for 3 disks

The shortest solution for three disks is 1→3, 1→2, 3→2, 1→3, 2→1, 2→3, 1→3, where the numbers are pegs. Solve it a few times until your hands know it, and four disks and more become much easier.
2. Think about the largest disk first

The largest disk can only move to the goal peg when every other disk is stacked on the middle peg. So a 4-disk puzzle splits into three steps: move the top three disks to the middle, move the largest disk to the right, then move the three disks from the middle on top of it. Moving three disks takes 7 moves, so the total is 7 + 1 + 7 = 15. Five disks take 15 + 1 + 15 = 31. Breaking a big problem into a slightly smaller copy of the same problem is the key idea of the Tower of Hanoi.
3. Your first move depends on the number of disks
To solve in the minimum number of moves, pay attention to where the smallest disk goes first. With an odd number of disks (3, 5, 7), move it to the goal peg on the right. With an even number (4, 6, 8), move it to the middle peg. Start the other way and you will have to take a detour somewhere.
4. The smallest disk always travels in the same direction

In the shortest solution, the smallest disk moves on every other turn and always cycles around the pegs in the same direction: 1 → 3 → 2 → 1 … with an odd number of disks, and 1 → 2 → 3 → 1 … with an even number.
5. Every other move has only one option
After moving the smallest disk, the next move must use a different disk, and there is always exactly one legal choice: look at the two pegs without the smallest disk and move the smaller of their top disks onto the other peg. Alternate “smallest disk in its fixed direction” with “the only other legal move,” and you can solve any number of disks in the minimum number of moves without thinking ahead. This simple routine is the iterative Tower of Hanoi algorithm.
6. The recursive algorithm
If you are studying programming, the Tower of Hanoi is the classic example of recursion, and the idea from tip 2 translates directly into code. To move n disks from peg A to peg C using peg B as the spare:
move(n, A, C, B): # n disks from A to C, spare B
if n == 0: return
move(n − 1, A, B, C) # clear the way
move disk n from A to C # the largest disk
move(n − 1, B, C, A) # rebuild on top
If M(n) is the number of moves for n disks, the steps give M(n) = 2 × M(n − 1) + 1 with M(1) = 1, which works out to exactly 2n − 1. It is also a neat proof that you can’t do better: the largest disk has to move at least once, and before and after that move the other n − 1 disks must be moved as a complete tower.
7. Use the hint and the demo when you are stuck
Press Hint to see an arrow for the next move on the shortest path from where you are now. Even if you have wandered off the best route, the hint always counts from your current position, and pressing Hint a second time makes the move for you. Demo plays the rest of the solution automatically at one of three speeds, and “Stop and take over” hands control back at any time. Games where you used a hint, the demo or undo aren’t counted toward your personal best.
Tower of Hanoi FAQ
What is the minimum number of moves?
With three pegs and n disks, the minimum is 2n − 1 moves: 7 for 3 disks, 15 for 4, 31 for 5, 63 for 6, 127 for 7 and 255 for 8.
How long would 64 disks take?
264 − 1 is 18,446,744,073,709,551,615 moves. At one move per second without a break, that would take about 585 billion years, far longer than the universe has existed so far.
What is the minimum with four pegs?
9 moves for 4 disks, 13 for 5, 17 for 6, 25 for 7 and 33 for 8. These numbers come from the Frame–Stewart algorithm. Whether it is really optimal for four pegs was an open question for decades, and a proof was announced in 2014. For five or more pegs it is still unproven.
When does the timer start?
With your first move, and it stops when the puzzle is solved. Time spent planning before your first move doesn’t count. Personal bests are saved on this device for each number of disks and each rule.
Can I stop and continue later?
Yes. Open the page again in the same browser on the same device and press Continue to pick up with the same disks and move count. Sound is off at first; press “Sound: off” to hear a click when a disk lands and a chime when you finish.
The history of the Tower of Hanoi
The Tower of Hanoi was invented by the French mathematician Édouard Lucas and sold as a toy in 1883. He first published it under a made-up name, “N. Claus de Siam,” which is an anagram of “Lucas d’Amiens.” The puzzle came with a legend: in a temple in India, priests were moving 64 golden disks between three diamond needles according to these rules, and when they finished, the world would end. The story was Lucas’s own invention, but as the 64-disk calculation above shows, nobody needs to worry.
Today the puzzle is used in math classes to explore patterns and powers of two, in computer science courses to teach recursion, and in psychology as a test of planning. Most of all, it remains a satisfying puzzle to solve: start with three disks, work your way up to eight, and see if you can hit the minimum every time.