AbraCalc

Tower of Hanoi

Solve the Tower of Hanoi puzzle in your browser. Move all discs to the rightmost peg!

Tower of Hanoi
Moves: 0   Best possible: 7

Click a peg to pick up / place the top disc

Embed this tool on your site
Cite this tool

APA

AbraCalc. (2026). Tower of Hanoi [Online calculator]. Retrieved from https://abracalc.com/game/tower-of-hanoi/

BibTeX

@misc{abracalc-tower-of-hanoi, author = {AbraCalc}, title = {Tower of Hanoi}, year = {2026}, howpublished = {\url{https://abracalc.com/game/tower-of-hanoi/}} }

Did this tool answer your question?

How to play

  1. Click a peg to pick up its top disc (it will highlight in orange).
  2. Click another peg to place the disc there — you can't place a larger on a smaller.
  3. Move all discs from Peg A to Peg C using as few moves as possible.
  4. Select 3, 4, or 5 discs using the dropdown; click Restart any time.

Click a peg to select the top disc, then click another peg to move it. You can only place a smaller disc on a larger one. Move all discs to Peg C!

How it works

Tower of Hanoi is a classic mathematical puzzle consisting of three pegs and a stack of discs of decreasing size. All discs start on the leftmost peg and your goal is to move the entire stack to the rightmost peg.

Two rules govern every move: you may only move one disc at a time, and you may never place a larger disc on top of a smaller one. These constraints mean the optimal solution for n discs always requires exactly 2^n minus 1 moves.

The puzzle is a popular introduction to recursive thinking in computer science because the solution naturally breaks into three recursive sub-problems. Playing it yourself builds spatial reasoning and forward-planning skills.

In this browser version, click a disc or its peg to pick it up, then click the destination peg to drop it. Illegal moves are blocked automatically so you can explore freely without breaking the rules.

Worked example

Solving the 3-disc puzzle optimally

  1. Move the smallest disc (disc 1) from peg A to peg C.
  2. Move disc 2 from peg A to peg B.
  3. Move disc 1 from peg C to peg B.
  4. Move disc 3 from peg A to peg C.
  5. Move discs 1 and 2 from peg B to peg C using peg A as spare (3 more moves).

All three discs stacked on peg C in 7 moves, the minimum possible.

Common mistakes to avoid

  • Moving the largest disc too early before clearing the pegs that will receive it.
  • Losing track of which peg is the spare and which is the destination during recursive sub-steps.
  • Attempting more discs than you have a strategy for; start with 3 discs until the pattern is clear.

Key terms

Peg
One of the three vertical rods on which discs are stacked.
Recursive solution
A problem-solving approach where the same strategy is applied to smaller versions of the same problem.
Optimal moves
The minimum number of moves to solve the puzzle, equal to 2^n - 1 where n is the disc count.

Frequently asked questions

What is the minimum moves?
The minimum number of moves is 2^n − 1. For 3 discs that is 7, for 4 discs 15, and for 5 discs 31.
Can I move any disc?
No — you can only move the topmost disc from any peg, and never place a larger disc on a smaller one.