Tower of Hanoi

Tap a peg to lift its top disk, then tap another peg to drop it. Move all disks to the right-hand peg in as few moves as possible.

Moves 0 / 150:00

Tap a peg to pick up its top disk, then tap the peg where it should go. On a keyboard, press 1, 2 and 3. “Show solution” finishes the puzzle from wherever you are.

How to play

  1. All disks start on the left peg, the largest at the bottom.
  2. Move one disk at a time: lift the top disk of any peg and place it on another peg.
  3. A disk may only be placed on an empty peg or on a larger disk.
  4. Get the whole tower onto the right-hand peg.

The minimum number of moves

With n disks the puzzle needs at least 2ⁿ − 1 moves: 7 for 3 disks, 15 for 4, 31 for 5, up to 255 for 8. The solution is recursive: move the top n − 1 disks out of the way, move the largest disk, then move the n − 1 disks on top of it again.

Tips and background

  • The smallest disk moves every second turn, always in the same circular direction.
  • With an odd number of disks, move the smallest disk to the target peg first; with an even number, to the middle peg.
  • The puzzle was invented by the French mathematician Édouard Lucas in 1883. Psychologists use it to study planning and problem solving.

Frequently asked questions

How many moves does it take?

At least 2ⁿ − 1 moves for n disks – for example 15 moves for 4 disks and 63 for 6.

Is the game free?

Yes, free with no sign-up. Your best result for each number of disks is saved in your browser.

Can I undo a move?

Yes. Undo takes back your moves one by one; it still counts as a move.

What does “Show solution” do?

It finishes the puzzle in the fewest possible moves, starting from your current position. That round does not count as a best result.

Related tools