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.

Time0:00
Moves0
Rate Hanoi:

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

ObjectiveRebuild 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 areaThree pegs and a stack of discs that always grow larger toward the bottom
DifficultyElegant and logical
SolvabilityAlways solvable in a known, minimum number of moves
Board options3 discs, 4 discs, 5 discs, 6 discs
CategoryLogic puzzle

Learn Hanoi in five steps

The goal - Tower of Hanoi

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 - Tower of Hanoi

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 - Tower of Hanoi

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 - Tower of Hanoi

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 - Tower of Hanoi

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.

  1. 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).
  2. 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.
  3. 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.
  4. Never move the same disc twice in a row; doing so just reverses progress and is the classic way to loop forever.
  5. 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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 .

More puzzles to try

Slide Puzzle
Slide the numbered tiles into order around one empty square.
Sliding · Easy to learn, hard to master
2048
Swipe to slide tiles, merge matching numbers, and build the 2048 tile.
Sliding · Simple rules, deep endgame
Lights Out
Press cells to flip lights and their neighbours until the whole grid is dark.
Logic · A true logic puzzle
Nonogram
Use the number clues to fill the right cells and reveal a hidden picture.
Logic · Deductive and rewarding
Memory Match
Flip cards two at a time and remember where each symbol hides to make every pair.
Memory · Relaxing but sharp
Block Puzzle
Drag shaped blocks onto the grid and clear full rows and columns before you run out of room.
Blocks · Easy to start, endless to master
Flood It
Flood the whole board with one colour, spreading from the corner in as few moves as you can.
Color · Quick and clever
Word Search
Hunt hidden words in a grid of letters, running in any direction.
Word · Relaxing and searchable
Sokoban
Push every box onto a target square without boxing yourself in.
Logic · Logical and moreish
Water Sort
Pour the colours between tubes until each tube holds just one.
Color · Relaxing but tricky
Klotski
Slide the blocks aside to free the big square through the exit.
Sliding · A sliding-block classic
Simon
Watch the colours flash, then repeat the ever-growing sequence.
Memory · A memory endurance test
Rush Hour
Slide the cars and trucks out of the way to drive the red car to the exit.
Sliding · A sliding logic jam
Dot Connect
Connect each pair of coloured dots and fill the whole grid, no crossings.
Logic · Connect-the-dots logic
Peg Solitaire
Jump pegs over each other to remove them, aiming to leave just one.
Logic · A classic board puzzle
Word Scramble
Rearrange the jumbled letters to spell each hidden word.
Word · A quick word game