Spatial puzzle
Tower of Hanoi: Move the Whole Tower in the Fewest Moves
Play the Tower of Hanoi free in your browser with 3 to 7 rings. Learn why the minimum is 2ⁿ − 1 moves and how the recursive method works. Undo and hints.
Tower of Hanoi
Move one ring at a time, never onto a smaller ring, and rebuild the tower on pillar C.
How it plays
The Tower of Hanoi is a puzzle with three pillars and a stack of rings that get smaller towards the top. All the rings start on pillar A. Your job is to move the whole tower to pillar C, one ring at a time, without ever putting a larger ring on top of a smaller one. It plays right here in your browser with nothing to download. Start with three rings, which takes as few as seven moves, then work your way up to seven rings and 127 moves. Below the board you will find the rules, the formula for the minimum number of moves and the recursive method that reaches it.
How to play
Tap or click a pillar to pick up its top ring, then tap the pillar you want to move it to. The destination must be empty or have a larger ring on top. Choosing the same pillar twice puts the ring back down, and the game tells you when a move is not allowed. Each ring shows its size, from 1 for the smallest to 7 for the largest.
- Moves counts the moves you have made on this tower.
- Minimum shows the fewest moves this size can be solved in.
- Your best shows your lowest completed move count for this size.
There are five sizes: 3, 4, 5, 6 and 7 rings. Choose one from the ring menu and press Start tower. If the tower in front of you is unfinished, the game asks before replacing it; your best scores are kept either way.
Undo takes back one move at a time, all the way to the start, and it also works after the tower is complete. Hint selects the pillar whose top ring should move next on a shortest route and outlines where that ring should go; you still choose the destination. When every ring reaches pillar C, the game tells you how many moves you used and whether that was the minimum. Next tower starts the next size up, as far as 7 rings, and Play again restarts the size you just finished.
On a keyboard, press 1, 2 or 3 to choose pillars A, B or C. You can also Tab to a pillar, move between pillars with the left and right arrow keys (Home and End jump to A and C) and press Enter or Space to choose. Escape clears a selection.
The current tower, its moves and your best scores are saved in this browser on this device, so you can close the page and carry on later. No account is needed.
Rules
- Move one ring at a time, and only the top ring of a pillar.
- A ring can go onto an empty pillar or onto a larger ring, never onto a smaller one.
- The tower is complete when every ring is stacked on pillar C.
The minimum number of moves: 2ⁿ − 1
With n rings, the fewest moves that can complete the tower is 2ⁿ − 1. That is 2 multiplied by itself n times, minus one.
| Rings | Working | Minimum moves |
|---|---|---|
| 3 | 2 × 2 × 2 − 1 | 7 |
| 4 | 2 × 7 + 1 | 15 |
| 5 | 2 × 15 + 1 | 31 |
| 6 | 2 × 31 + 1 | 63 |
| 7 | 2 × 63 + 1 | 127 |
The middle column shows why each extra ring roughly doubles the work. The largest ring has to move at least once. Just before its first move it must be alone on A with an empty pillar to go to, so every smaller ring is already stacked on the third pillar: that means moving a tower of n − 1 rings. After its last move onto C, the smaller rings are all together on another pillar and still have to be moved on top of it: another tower of n − 1 rings. So n rings need at least twice the minimum for n − 1 rings, plus one move for the largest ring. Starting from one ring, which takes one move, that rule gives 3, 7, 15, 31, 63 and 127, which is exactly 2ⁿ − 1, and the recursive method below always finishes in that many moves.
The recursive method
The same idea gives a method that always reaches the minimum. To move n rings from one pillar to another:
- Move the top n − 1 rings to the spare pillar.
- Move the largest ring to the target pillar.
- Move the n − 1 rings from the spare pillar onto it.
Steps 1 and 3 are smaller versions of the same puzzle, so you apply the method again inside them, until you are moving a single ring. For three rings it unfolds into these seven moves:
- Ring 1 from A to C
- Ring 2 from A to B
- Ring 1 from C to B (the top two rings are now on B)
- Ring 3 from A to C
- Ring 1 from B to A
- Ring 2 from B to C
- Ring 1 from A to C (all three rings are on C)
Moves 1 to 3 shift a two-ring tower to B, move 4 is the largest ring, and moves 5 to 7 shift the two-ring tower onto C. Try it on the board above: the result line reads "All rings home in the minimum 7 moves."
A pattern you can follow without counting
Thinking recursively gets harder with six or seven rings, but the minimum solution also follows a simple rhythm:
- Every odd-numbered move uses the smallest ring, and it always travels in the same direction around the pillars. With an odd number of rings (3, 5 or 7) it goes A → C → B → A. With an even number (4 or 6) it goes A → B → C → A.
- Every even-numbered move does not touch the smallest ring. There is only one legal move that leaves it alone, so make that one.
Following those two rules from the start position completes every size here in the minimum number of moves. It also shows how often each ring moves: the smallest ring moves on every second move, the next ring half as often, and the largest ring exactly once. With seven rings, ring 1 moves 64 times and ring 7 moves once.
Tips and strategy
Decide where the first ring goes. The first move sets the direction for everything after it. With an odd number of rings, ring 1 goes straight to C; with an even number, it goes to B.
Think in towers, not single rings. To free a large ring, you need everything above it moved out of the way as one smaller tower. Ask which pillar that smaller tower should end up on.
Use Hint to get back on track. If your move count has drifted above the minimum, Hint shows the next move on a shortest route from where you are now, so you can still finish without starting over.
Step up one ring at a time. Each new size repeats the previous one twice with a single large move in between, so a size you have mastered becomes part of the next.
FAQ
What is the minimum number of moves in the Tower of Hanoi?
2ⁿ − 1, where n is the number of rings: 7 moves for 3 rings, 15 for 4, 31 for 5, 63 for 6 and 127 for 7. Each extra ring doubles the previous minimum and adds one.
How do you solve the Tower of Hanoi with 4 rings?
It takes 15 moves. Move the top three rings from A to B, using C as the spare (7 moves). Move ring 4 from A to C (1 move). Then move the three rings from B onto C, using A as the spare (7 moves). Because 4 is an even number, the very first move puts the smallest ring on B, not on C.
What does the Hint button do?
It works out a shortest route from the position in front of you to a finished tower on pillar C, selects the pillar whose top ring moves next and outlines the pillar it should go to. You still make the move yourself. It works from any position, including one where earlier moves have left the shortest path.
Does a solve count if it takes more than the minimum?
Yes. The tower is complete as soon as every ring is on pillar C, however many moves it took. The result tells you whether you matched the minimum, and Your best keeps your lowest completed move count for each size.
Can I finish the tower on pillar B?
No. Every tower starts on pillar A and has to be rebuilt on pillar C, the target. Stacking every ring on B is a legal position, but the game carries on until all the rings are on C.
Is my progress saved?
Yes, in this browser on this device, when browser storage is available. The current tower, every move made on it and your best score for each size are kept, so reloading the page brings the same tower back. There is no account, and clearing site data removes the save.
More puzzles
If you like planning a long sequence of moves, try Peg Solitaire, where every jump removes a peg, or Sokoban, where one careless push can trap a crate. You can also browse the logic puzzles or see all games.
Players’ notes
Stuck on a board, or found a trick worth sharing? Leave a note. No account needed.








No notes yet. Yours would be the first.