What Is Tower of Hanoi?

A free online Tower of Hanoi puzzle game. Challenge yourself with 3-7 disks and move the entire stack from peg A to peg C. You can only move one disk at a time and you can never place a larger disk on a smaller one. Use the Auto Solve feature to watch the optimal recursive solution in action, perfect for understanding algorithmic thinking.

The Tower of Hanoi is a classic mathematical puzzle invented by French mathematician Edouard Lucas in 1883. It consists of three pegs and a stack of disks of different sizes. The objective is to move the entire stack from the first peg to the last peg, following three simple rules: only one disk can be moved at a time, only the top disk on a peg can be moved, and no larger disk may be placed on a smaller one.

Start by selecting the number of disks (3 to 7). More disks exponentially increase the difficulty — the minimum number of moves required is 2^n - 1. With 3 disks, you need at least 7 moves. With 7 disks, you need 127 moves. The puzzle is a perfect demonstration of recursive thinking: to move n disks, you first move n-1 disks to the auxiliary peg, then move the largest disk, then move the n-1 disks on top of it.

Click a peg to pick up the top disk, then click another peg to place it. The game enforces the rules visually: if you try to place a larger disk on a smaller one, the move is rejected. The move counter tracks how many moves you have made, displayed against the minimum possible moves.

The Auto Solve feature demonstrates the optimal recursive solution. Watch as the algorithm efficiently moves all disks to the target peg in exactly 2^n - 1 moves. Each move is animated so you can study the pattern. The visual win detection triggers congratulations when you complete the puzzle.

Real-World Use Cases for Tower of Hanoi

Learning Recursive Problem Solving with 3 Disks

A programming student starts with 3 disks. The minimum moves are 7. They try to solve it manually, making 12 moves. Then they click Auto Solve to watch the optimal solution in 7 moves. The recursive pattern becomes clear: move 2 disks to B, move the largest to C, move 2 disks from B to C.

Challenging Yourself with 7 Disks

An experienced puzzler selects 7 disks — minimum 127 moves. They work through the puzzle over 20 minutes, using the move counter to track progress. The recursive strategy is essential: thinking about the problem as smaller sub-problems rather than individual disk moves.

Demonstrating the Recursive Algorithm in a Classroom

A computer science teacher shows Tower of Hanoi with 4 disks. First, students try manually. Then Auto Solve demonstrates the optimal 15-move solution. The teacher pauses after key steps to explain: "Now we need to move 3 disks from peg A to peg B, using peg C as auxiliary."

Why Use Tower of Hanoi?

  • 3-7 disks with interactive drag-free peg clicking
  • Auto Solve demonstrates the optimal recursive solution
  • Move counter tracks your progress
  • Visual win detection with congratulations

How to Use Tower of Hanoi — Step by Step

1

Choose the number of disks (3-7).

2

Click a peg to pick up the top disk.

3

Click another peg to place it.

4

Move all disks to peg C to win!

Who Is Tower of Hanoi Best For?

  • puzzle lovers
  • programming students
  • math enthusiasts
  • problem solvers

Pro Tips for Tower of Hanoi

  • 1The minimum number of moves for n disks is 2^n - 1. For 3 disks: 7 moves. 4: 15. 5: 31. 6: 63. 7: 127. The exponential growth is why 8+ disks are impractical for manual solving.
  • 2The recursive solution follows a simple pattern: to move n disks from source to target, (1) move n-1 disks from source to auxiliary, (2) move the largest disk from source to target, (3) move n-1 disks from auxiliary to target.
  • 3For an odd number of disks, the first move should go to the target peg. For an even number, the first move goes to the auxiliary peg. This pattern minimizes total moves.
  • 4The Tower of Hanoi is used in psychological research on problem-solving strategies and in computer science curricula to teach recursion. It is also the basis for the Tower of London test of executive function.

Tower of Hanoi — Frequently Asked Questions

What is the minimum number of moves?

For n disks, the minimum is 2^n - 1 moves. For 4 disks, that's 15 moves. For 7 disks, that's 127 moves.

Why can't I place a larger disk on a smaller one?

That's the rule! The puzzle requires that disks are always in decreasing size from bottom to top on every peg.

Are these games and tools free to use?

Yes, all interactive tools, games, and visualizations are completely free with no limits, ads, or paywalls. They run entirely in your browser.

Do I need a powerful computer to run these?

No. The tools are optimized for performance on standard hardware. Pixel art, fractals, and sorting visualizations run smoothly on most devices including tablets.

Is Tower of Hanoi really free to use?

Yes, Tower of Hanoi is completely free with no hidden charges, no usage limits, and no premium tiers. You can use it as often as you need without signing up or providing any personal information.

Ready to Use Tower of Hanoi?

Free online tool — works in your browser, no sign-up required. Start using it right now.

Try It Now
Free Forever · No Sign-up

182 Free Tools at Your Fingertips

All free online tools for developers, designers, students, and creators. Every tool works in your browser — no sign-up, no data collection.