Tower of Hanoi

Moves: 0 Best possible: 7 Time: 0:00

Move all the disks to the right peg

Best: —

Tap a peg to lift its top disk, then tap a destination. Drag also works. Arrows move focus; Enter or Space acts. Keys 1–3 pick a peg. Esc puts a disk back; U, H and R are Undo, Hint and Restart.

About Tower of Hanoi

The Tower of Hanoi is a one-player puzzle with three pegs and a stack of disks of different sizes. French mathematician Édouard Lucas invented it, and it was first sold in 1883. The puzzle came with a legend about priests in a temple moving 64 golden disks. Finishing that tower would take 2^64 − 1 moves, more than 18 quintillion. The story makes the scale memorable, even though this page offers much shorter towers.

The smallest standard tower here has three disks and needs at least seven moves. Four disks need 15, five need 31, six need 63, and seven need 127. In general, a tower of n disks needs at least 2^n − 1 moves from the usual start. This puzzle is a classic way to teach recursion in mathematics and computer science: the same small plan repeats inside a larger plan.

How to play

Move every disk to the right peg, marked Goal. Only the top disk on a peg may move, and a bigger disk may never be placed on a smaller one. The middle peg is a useful stopping point, but a full stack there does not win. Choose a standard tower of 3, 4, 5, 6 or 7 disks, all starting on the left. Daily starts with five disks scattered across the pegs and shows the fewest moves possible for that particular position. Every position can be solved.

On a phone, tap a peg to lift its top disk, then tap the destination. Tap the original peg again to put it back. A legal empty peg with only one disk that can reach it can also be tapped once to move that disk. You can drag a top disk to another peg. Mouse clicks and drags work the same way. With a keyboard, Left and Right move focus among pegs; Enter or Space acts on the focused peg. Keys 1, 2 and 3 select pegs directly, while Esc puts a lifted disk back. Undo, Hint, Restart and New game are below the board; U, H and R are shortcuts.

Tips

To move a tower, first move everything above its biggest disk to the spare peg. Move that biggest disk, then rebuild the smaller tower on top of it. The smallest disk moves every other turn and always travels in the same direction around the three pegs. With an odd number of disks, its first move goes to the goal peg; with an even number, it goes the other way. Between two moves of the smallest disk, only one other legal move remains. Start with three disks, then add one at a time. Use Hint when stuck and Undo freely while you learn the pattern.

FAQ

Is it free?

Yes. Play free in your browser with no download or account.

What is the fewest number of moves?

For a standard start with n disks, the fewest moves is 2^n − 1: 7 for 3 disks, 15 for 4, 31 for 5, 63 for 6, or 127 for 7. Daily shows its own best possible count.

Can I get stuck?

No. Every legal position can still be solved. Use Hint for a move toward the goal or Undo to try another route.

What is the Daily puzzle?

Daily starts with five disks scrambled across the pegs. The same date gives everyone the same position, with a best possible count of at least 15 moves.

Is it OK for kids?

Yes. Start with three disks, then add more as you learn. Hint and Undo help you practise.

Does it work on phones?

Yes. Tap one peg to lift a disk and another to drop it, or drag the disk. If exactly one disk can reach an empty peg, tap it directly.