Home/Blog/How to Solve Tower of Hanoi | Step-by-Step Puzzle Guide

How to Solve Tower of Hanoi | Step-by-Step Puzzle Guide

By PlayBrain Teamยทยท7 min read

Tower of Hanoi is one of those puzzles that looks completely impossible the first time you see it, and completely obvious once you understand the pattern.

The gap between "impossible" and "obvious" is just one key insight. Once you have it, you can solve any Tower of Hanoi puzzle โ€” 3 discs, 5 discs, 8 discs โ€” in the minimum number of moves, every time.

Play Tower of Hanoi free in your browser โ€” no download โ†’

The Rules (Quick Recap)

  • You have 3 pegs and a stack of discs on the leftmost peg, largest disc at the bottom
  • Move the entire stack to the rightmost peg
  • Only move one disc at a time
  • Never place a larger disc on a smaller disc

That's it. Three rules. The puzzle is 100% solvable for any number of discs, but it requires a specific approach.

The Core Insight: Think Recursively

Here's the key that unlocks everything: to move N discs, you only need to think about moving N-1 discs.

The logic:

  1. Move the top N-1 discs to the middle peg (ignore how for now โ€” it's the same problem, just smaller)
  2. Move the bottom (largest) disc from the left peg to the right peg
  3. Move the N-1 discs from the middle peg to the right peg (same problem again, same smaller size)

You're not solving the whole puzzle at once. You're solving tiny versions of the same puzzle over and over. This is called a recursive algorithm, and it's the same logic used in computer science to solve complex problems by breaking them into simpler ones.

Step-by-Step: 3 Discs Solved

Let's walk through it completely. We have discs 1 (smallest), 2, 3 (largest) on the left peg. Goal: move everything to the right peg. Middle peg is the helper.

Move 1: Disc 1 โ†’ Right peg

Move 2: Disc 2 โ†’ Middle peg

Move 3: Disc 1 โ†’ Middle peg (on top of disc 2)

Move 4: Disc 3 โ†’ Right peg

Move 5: Disc 1 โ†’ Left peg

Move 6: Disc 2 โ†’ Right peg

Move 7: Disc 1 โ†’ Right peg

Done! 7 moves. That's the minimum for 3 discs.

If you trace through the logic, you'll see the recursive pattern: steps 1-3 move the top 2 discs to the middle, step 4 moves the big disc, and steps 5-7 move the top 2 discs again to the right.

The Minimum Moves Formula

The minimum number of moves for N discs is 2^N - 1.

  • 1 disc: 1 move
  • 2 discs: 3 moves
  • 3 discs: 7 moves
  • 4 discs: 15 moves
  • 5 discs: 31 moves
  • 6 discs: 63 moves
  • 8 discs: 255 moves

The puzzle grows exponentially. A 64-disc version would take 2^64 - 1 = 18.4 *quintillion* moves. At one move per second, that's over 580 billion years โ€” which is why the ancient legend that moves a 64-disc Temple of Brahma ends the world carries a certain mathematical weight.

For the online version, you'll typically face 3-7 discs. Even 7 discs at 127 minimum moves is doable in a few minutes once you know the pattern.

The Recursive Algorithm in Plain English

Here's the same idea written as a simple procedure:

To move N discs from Source to Destination using Helper:

  1. If N = 1, just move the single disc from Source to Destination. Done.
  2. Otherwise:

- Move top N-1 discs from Source to Helper (using Destination as helper)

- Move disc N from Source to Destination

- Move N-1 discs from Helper to Destination (using Source as helper)

The genius is step 1: the base case. If you have 1 disc, you can always move it directly. Every other case reduces to moving smaller stacks until you hit that base case. The puzzle solves itself.

Tips for Playing the Online Version

Don't rush. This is not a speed puzzle โ€” it's a logic puzzle. Pausing to think before each move saves you from having to undo and redo sequences.

Plan your base move first. Before anything, decide which peg the largest disc needs to reach. Everything else flows from that.

Use the "always move the smallest disc every other move" trick. In a 3-disc puzzle, moves 1, 3, 5, 7 all involve the smallest disc. The even-numbered moves (2, 4, 6) always involve a non-smallest disc. Following this pattern keeps you on the optimal path automatically.

Odd-numbered disc counts go right, even-numbered go left โ€” at least for the first move of the smallest disc. For 3 discs (odd), move disc 1 to the right peg first. For 4 discs (even), move disc 1 to the middle (left auxiliary) peg first. This is a useful heuristic if you lose track of the pattern mid-puzzle.

Don't undo repeatedly. If you've made a series of wrong moves and are confused about the state, it's usually faster to restart than to try to backtrack. The puzzle is short enough that a fresh start costs less than trying to debug a tangled board.

Why Tower of Hanoi Matters Beyond the Game

Tower of Hanoi is used in:

  • Computer science education โ€” it's the classic example of recursion and is often one of the first recursive algorithms students learn to write
  • Psychological research โ€” it's a standard benchmark for measuring executive function, planning ability, and working memory
  • Backup tape rotation โ€” the "Towers of Hanoi rotation" was a real algorithm used to schedule magnetic tape backups in a way that minimized tape wear

The puzzle itself was invented by French mathematician ร‰douard Lucas in 1883. It remains one of the most elegant demonstrations of exponential growth and recursive thinking ever devised.

What to Try Next

Once you've solved 3-4 discs, try working your way up to 6 or 7. The method is identical โ€” just more repetitions of the same recursive pattern.

If you want to keep challenging your brain with logic puzzles, try Rush Hour (block-sliding logic) or Laser Reflect (optical path puzzles). And for a classic board game that rewards deep sequential thinking, Chess or Checkers builds the same kind of multi-step planning muscle.

Get weekly game picks in your inbox

New games, tips, and challenges every week. No spam.

Frequently Asked Questions about How to Solve Tower of Hanoi | Step-by-Step Puzzle Guide

How do you solve Tower of Hanoi step by step?
For 3 discs: move disc 1 to right peg, disc 2 to middle peg, disc 1 to middle peg, disc 3 to right peg, disc 1 to left peg, disc 2 to right peg, disc 1 to right peg. That is 7 moves โ€” the minimum. The pattern scales recursively for more discs.
What is the minimum number of moves to solve Tower of Hanoi?
The minimum moves formula is 2^N - 1, where N is the number of discs. For 3 discs: 7 moves. For 4 discs: 15 moves. For 7 discs: 127 moves. The puzzle grows exponentially โ€” a 64-disc version would take over 18 quintillion moves.
What is the algorithm for solving Tower of Hanoi?
The recursive algorithm: to move N discs from Source to Destination using Helper, first move the top N-1 discs from Source to Helper, then move the largest disc from Source to Destination, then move the N-1 discs from Helper to Destination. This repeats recursively until N equals 1.
What skills does Tower of Hanoi test?
Tower of Hanoi tests executive function, planning ability, and working memory. It is used in psychology research as a benchmark for measuring cognitive planning. It also demonstrates recursion and exponential growth, making it a classic computer science teaching tool.
P

PlayBrain Team

Our editorial team reviews and tests every game and guide we publish. Have a question or correction? Get in touch.