cools maths gamesSurprise me

Tower of Hanoi

Move a whole stack of rings to the right-hand peg, one at a time, never setting a larger ring on a smaller one.

Tower of Hanoi title screen
  • Works on mobile
Report a problem

Tower of Hanoi is the famous puzzle of three pegs and a stack of rings. All the rings start on the left peg, biggest at the bottom, and your goal is to rebuild the same stack on the right peg. This version shows your move count next to the best possible score and can play out the perfect answer for you.

How Tower of Hanoi Works

Only one ring moves at a time. You lift the top ring from a peg and drop it on another. A ring may land on an empty peg or on a bigger ring, never on a smaller one. While you hold a ring, it floats over the selected peg so you can see where it will go.

You start with three rings. The plus and minus icons change the stack size, and any change starts a fresh puzzle. Each drop adds one to the move counter, even if you put the ring back where it came from.

The counter reads like 9/7, meaning moves made over the minimum. That minimum is always one less than two raised to the number of rings.

Your First Few Minutes

  1. Look at the counter and note the target, which is 7 for three rings.
  2. Click the left peg to lift the smallest ring and drop it on the right peg.
  3. Move the middle ring to the center peg, then put the small ring on top of it.
  4. Shift the largest ring to the right peg and rebuild the rest over it.
  5. Press the play icon to watch the solver, then add a ring and try again.

Controls for Tower of Hanoi

Keyboard, mouse and touch controls for Tower of Hanoi
To do thisKeyboardMouseTouch screen
Pick up or drop a ringSpace, Enter, Up/Down arrows, or W/SClick a pegTap a peg
Move the selection between pegsLeft/Right arrows or A/Dnot usednot used
Restart the puzzleRClick the circular arrows iconTap the circular arrows icon
Add or remove a ringnot usedClick the plus or minus iconTap the plus or minus icon
Watch the puzzle solve itselfnot usedClick the play icon (click again to stop)Tap the play icon (tap again to stop)

What It Trains

Tower of Hanoi rewards planning in layers. To move a big ring, you first clear every smaller ring onto a spare peg, which is a smaller copy of the same puzzle. You also start to notice the repeating rhythm and the doubling pattern in the minimum move counts.

Strategy Notes

  • Check odd or even. With an odd ring count, the smallest ring first goes right. With an even count, it goes to the middle.
  • Alternate with the small ring. Every other move in a perfect run uses it, always circling the same way.
  • Take the only other move. Between small ring moves, just one legal move exists.
  • Break the stack down. Move all but the bottom ring aside, shift the bottom one, then rebuild.
  • Study the solver once. Four or five rings show the pattern clearly.

Good to Know

It works with a keyboard, mouse or touch, and the controls sit in the bottom corner on phones. Douile made the game and this site added click and tap controls and a restart button.

Tower of Hanoi questions and answers

How hard does it get?

Three rings take only seven moves, so the start is gentle. Every extra ring roughly doubles the work. Five rings need 31 moves, and keeping a perfect count gets harder as the stack grows.

When is the puzzle solved?

It is solved when the full stack sits on the right-hand peg in order. The board briefly zooms in and out to mark the finish, and the counter shows how your moves compare with the minimum.

Is there a time limit?

No. There is no clock, only the move counter. You can take as long as you want to think about each step, which makes it a good puzzle for slow, careful planning.

What is the smallest stack?

Three rings. The minus icon will not go lower than that. The plus icon adds more rings, and changing the number always starts a new puzzle.

Games that use logic like Tower of Hanoi

Different rules, same kind of thinking.

Try something from another shelf