Tower of Hanoi online: move the discs from one peg to another
In Tower of Hanoi you move a stack of discs from one peg to another, one disc at a time, never placing a larger disc on a smaller one. With n discs, the minimum is 2^n − 1 moves: 7 for three discs, 31 for five. Here are the rules, a table of minimum moves and the method that gets you there without losing track.
A free game in a few seconds, no sign-up needed.
What are the rules of Tower of Hanoi?
The board has three pegs. At the start, all the discs sit on one peg, largest at the bottom and smallest on top. The goal is to rebuild the same stack on another peg, following three rules:
- one disc moves at a time;
- you only pick up the top disc of a peg;
- a disc never goes on top of a smaller one.
In Kognify, the goal is to gather every disc on the right peg. Depending on the level, the starting position can vary: the on-screen instruction always reminds you which peg to finish on. Tower of Hanoi is one of the Premium games in Kognify.
How many moves does Tower of Hanoi take?
For the classic tower (all discs start on one peg and finish on another), the minimum is 2^n − 1 moves, where n is the number of discs. The Maths Careers page explains it with the recurrence M(n) = 2 × M(n − 1) + 1: move n − 1 discs, then the largest, then n − 1 discs again. Here is the table, computed by script:
| Discs | Minimum moves |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 7 |
| 4 | 15 |
| 5 | 31 |
| 6 | 63 |
| 7 | 127 |
| 8 | 255 |
Each extra disc doubles the minimum, then adds one move. This minimum applies to the classic tower: if a level starts from an already mixed position, the number of moves needed can be smaller.
The table also shows how a solution is built. For five discs, the 31 moves split into 15 to shift the top four discs aside, 1 for the largest disc, then 15 to bring the four discs back on top of it. Four discs follow the same pattern: 7 + 1 + 7 = 15. Reading the number of moves this way helps you check your progress: if you are far beyond the minimum, you probably repeated a position.
How do you solve Tower of Hanoi step by step?
To move n discs from the left peg to the right peg: move the top n − 1 discs to the middle peg, place the largest disc on the right, then bring the n − 1 discs from the middle onto the right. Each stage is the same tower in a smaller size, so the method works for any number of discs.
Three-disc example (disc 1 is the smallest; L, M and R are the left, middle and right pegs). The 7 moves:
- disc 1: L → R
- disc 2: L → M
- disc 1: R → M
- disc 3: L → R
- disc 1: M → L
- disc 2: M → R
- disc 1: L → R
A handy shortcut: the smallest disc moves every other turn, always in the same rotation. With an odd number of discs (3, 5, 7) it cycles L → R → M → L. With an even number (2, 4, 6, 8) it cycles L → M → R → L. Between two moves of the small disc, only one other move is legal: play it. We checked this rule by script for 3 to 8 discs.
What are the common mistakes?
- Moving the same disc twice in a row. This never happens in a shortest solution: the second move undoes or shortens the first.
- Picking the wrong middle peg. To send the stack to the right, the upper discs wait in the middle. The small disc's first move depends on parity: to the right with an odd number of discs, to the middle with an even number.
- Forgetting the smallest disc. When you are stuck, the smallest disc is often in the wrong place: every other move is its move.
- Going for the big disc too early. It can only move once all the others are stacked on the third peg.
One more habit that pays off: say out loud what you are trying to do before each move ("I am clearing the top three discs to reach the fourth"). It keeps the goal of the current stage in view, and you notice quickly when a move does not serve it. In the game you can also undo a move if you place a disc where you did not intend to.
Where does this puzzle come from?
The presentation pages we read credit Tower of Hanoi to Édouard Lucas in 1883 and tell a legend: a tower of 64 golden discs to be moved. According to the Maths Careers demonstration, that would take 2^64 − 1 moves, which is 18,446,744,073,709,551,615 moves. At one move per second, that is about 585 billion years. For the history of other reasoning games, read our article on the history of logic games.
How do you move up level by level?
In Kognify, the number of discs grows as the levels go by. A good approach: learn the small disc's rhythm on three discs first, then apply the same method to four and five. You do not need to calculate every move: once the rhythm is in your hands, each move becomes obvious. For other games where you plan several moves ahead, try our spatial planning games, our no-timer logic games or our pick of logical problem-solving games. You can also browse all Kognify games.
Frequently asked questions
Can Tower of Hanoi always be solved?
Yes, with three pegs and any number of discs. Moving n − 1 discs, then the largest, then n − 1 discs again always works. The number of moves grows quickly, but it stays finite.
How many moves for 5 discs?
31 moves at minimum, which is 2^5 − 1. For 4 discs it is 15; for 6 discs, 63.
Does Tower of Hanoi always have 3 pegs?
The classic version has three pegs. Variants with four or more pegs exist, but the 2^n − 1 minimum only applies to the three-peg version.
What is the legend of Tower of Hanoi?
The story goes that a tower of 64 golden discs has to be moved from one peg to another under the same rules. For 64 discs the minimum is 2^64 − 1 moves, a 20-digit number.
How do you solve Tower of Hanoi with 7 discs?
With the same method: 127 moves at minimum. Since 7 is odd, the smallest disc cycles L → R → M → L; between two moves of the small disc, play the only other legal move.
Ready to move your first tower?
Play Tower of Hanoi online and apply the small-disc method, level after level.
🎮 Play Tower of Hanoi →