Tower of Hanoi
Move a stack of graduated discs to another peg, never resting a big disc on a small one.The Tower of Hanoi is the classic 'move the tower' puzzle. You start with a neat stack of discs on the left peg, smallest at the top, and you must rebuild the whole stack on another peg. Two rules govern everything: you may only lift the top disc of a peg, and you may never place a larger disc on top of a smaller one. That single restriction turns a simple-looking task into a beautifully structured sequence. Hanoi is famous because its solution is perfectly recursive: to move a tower of n discs you first move the top n-1 discs out of the way, move the biggest disc across, then move that smaller tower back on top. Follow that idea and the puzzle is never guesswork - it can always be solved, and always in exactly 2^n - 1 moves, which is why four discs take fifteen moves and every extra disc roughly doubles the work.
You can play Tower of Hanoi free in your browser here - three pegs and a stack of discs that always grow larger toward the bottom. It is rated elegant and logical, and always solvable in a known, minimum number of moves. Choose from 3 discs, 4 discs, 5 discs or 6 discs. Your best times and solve counts save automatically, and you can take on the daily challenge whenever you like.
How Hanoi works
In short: Move a stack of graduated discs to another peg, never resting a big disc on a small one. The play area is three pegs and a stack of discs that always grow larger toward the bottom, it is rated elegant and logical, and always solvable in a known, minimum number of moves.
Key facts about Hanoi
| Objective | Rebuild the entire starting stack, in the same size order, on a different peg. The puzzle is won when every disc sits on the target peg. |
|---|---|
| Play area | Three pegs and a stack of discs that always grow larger toward the bottom |
| Difficulty | Elegant and logical |
| Solvability | Always solvable in a known, minimum number of moves |
| Board options | 3 discs, 4 discs, 5 discs, 6 discs |
| Category | Logic puzzle |
Learn Hanoi in five steps
The goal
Rebuild the entire starting stack, in the same size order, on a different peg. The puzzle is won when every disc sits on the target peg.
Moving a disc
Click a peg to pick up its top disc, then click another peg to drop it. You can only ever move the single topmost disc of a peg.
The golden rule
A disc may only be placed on an empty peg or on top of a larger disc. Dropping a big disc onto a smaller one is never allowed.
Think in sub-towers
To shift a tall stack, first move the smaller tower above your target disc onto the spare peg, move the big disc, then move that tower back - the same idea repeats all the way down.
Winning
The moment the full stack is reassembled on a new peg you have solved it. Matching the minimum move count of 2^n - 1 is the mark of a perfect solve.
Where Hanoi came from
The Tower of Hanoi was published in 1883 by the French mathematician Édouard Lucas, who sold it as a toy under the pen name "N. Claus de Siam", an anagram of "Lucas d'Amiens". From the start it came wrapped in a memorable story.
Lucas attached a legend about a group of priests in a great temple who were forever moving a tower of sixty-four golden discs between three diamond needles, obeying the same two rules as the puzzle. When they finished, the legend said, the world would end - a nice way to hint at just how many moves sixty-four discs really require.
The puzzle became a fixture of recreational mathematics and, later, of computer science education, where its clean recursive solution makes it the standard first example of a function that calls itself. More than a century on, it remains one of the most widely taught puzzles in the world.
Tips to solve Hanoi faster
💡 Best move: Solve it recursively in your head: 'to move this stack, I first need to move the stack above the bottom disc onto the free peg' - repeat that thought and the moves reveal themselves.
- Follow the small-disc rhythm: the smallest disc moves on every other turn, always travelling in the same rotating direction (for an even number of discs it circles one way, for odd the other).
- Between smallest-disc moves there is only ever one other sensible legal move, so if you never undo your last move the whole path is essentially forced.
- Pick your spare peg deliberately - the peg that is neither the source nor the destination of the disc you are about to move is your working space.
- Never move the same disc twice in a row; doing so just reverses progress and is the classic way to loop forever.
- Count as you go. The target is 2^n - 1 moves (7 for three discs, 15 for four, 31 for five), so your move counter tells you at a glance whether you are still on the optimal path.
Sharper tactics for Hanoi
- Memorise the alternating pattern: move the smallest disc, then make the only non-reversing move available, and repeat. That two-beat cycle solves any Hanoi optimally without ever thinking about the recursion again.
- For the smallest disc, keep it cycling in a fixed direction around the three pegs - the direction depends only on whether the disc count is odd or even, so decide it once at the start.
- Recognise that the puzzle is self-similar: the sequence to move five discs literally contains the sequence to move four discs twice, so practising small towers builds the reflexes for large ones.
- If you lose your place, look at the smallest disc. If it just moved, your next move is the forced one elsewhere; if it did not just move, it is the smallest disc's turn again.
- Aim for the minimum move count as a discipline. Any solve that beats no rule but takes far more than 2^n - 1 moves means you undid work somewhere - trace back to find the wasted pair.
Mistakes that trip people up
- Moving discs without a plan - think recursively, moving the smaller tower off the big disc first, and the sequence solves itself.
- Moving the same disc twice in a row - that just undoes your last move, which is the classic way to loop forever without progress.
- Placing a larger disc onto a smaller one is illegal - always check the disc underneath before you drop, since only a bigger disc may support it.
- Losing track of the rhythm - the smallest disc should move every other turn in one fixed direction, so if it just moved, the next move is elsewhere.
Ways to play Hanoi
Three discs
The gentle introduction, solved in just seven moves - short enough to reveal the whole pattern at a glance.
Four and five discs
The classic middle ground at fifteen and thirty-one moves, long enough to feel the recursion but short enough to solve by hand comfortably.
Six discs
A sixty-three move tower that really tests whether you have internalised the rhythm rather than memorised a sequence.
Four-peg Frame-Stewart
A well-known extension adds a fourth peg, which lowers the minimum number of moves and opens a surprisingly subtle optimisation problem.
Hanoi questions, answered
How many moves does the Tower of Hanoi take?
The minimum number of moves for n discs is 2 to the power of n, minus one. That is 7 moves for three discs, 15 for four, 31 for five and 63 for six. Each disc you add roughly doubles the length of the shortest solution.
Can the Tower of Hanoi always be solved?
Yes, always. For any number of discs there is a guaranteed solution, and in fact a guaranteed shortest solution. There is no arrangement of a legal Hanoi position that cannot be finished, which is part of what makes the puzzle so satisfying to teach.
What are the rules of the Tower of Hanoi?
There are just two. You may move only one disc at a time, taking the top disc from a peg, and you may never place a larger disc on top of a smaller one. Everything else follows from those two constraints.
What is the trick to solving it quickly?
The fastest reliable method is the alternating rule: on odd turns move the smallest disc one step in a fixed direction, and on even turns make the only other legal move that does not undo your last one. Repeat until the tower is rebuilt.
Why is it called the Tower of Hanoi?
The French mathematician Édouard Lucas introduced it in 1883 wrapped in a legend about priests in a temple - sometimes placed in Hanoi or in a temple of Brahma - moving 64 golden discs. The exotic framing stuck and gave the puzzle its name.
How long would 64 discs take?
The legend says the world ends when the priests finish moving 64 discs. At one move per second that would take about 585 billion years - far longer than the age of the universe - because 2 to the power of 64 minus one is an astronomically large number of moves.
Is the Tower of Hanoi used in computer science?
Very much so. It is the textbook example for teaching recursion, because the elegant solution is defined in terms of solving two smaller copies of itself. Students meet it in almost every introductory programming course.
Still curious about Tower of Hanoi? Browse the full puzzle FAQ, look up a term such as logic puzzle in the puzzle glossary, or compare Hanoi with the other games in the rules for every puzzle.
Last updated .