Tower of Hanoi — Free

The classic recursion puzzle. Move the whole stack of disks onto the last peg one at a time — and never drop a bigger disk on a smaller one.

Moves
0
Minimum
7
Best

Solved! 🎉

Click the start peg to pick up its top disk.

What is Tower of Hanoi?

Tower of Hanoi is a classic mathematical puzzle invented by the French mathematician Édouard Lucas in 1883. You begin with a neat stack of different-sized disks piled on one of three pegs, largest on the bottom and smallest on top, and your goal is to move the entire stack onto another peg. The catch is simple but strict: you may move only one disk at a time, you can only lift the disk currently sitting on top of a peg, and you must never set a larger disk on top of a smaller one. Those three rules turn a task that looks trivial into a genuinely satisfying test of planning and patience.

What makes Tower of Hanoi beloved by mathematicians and computer-science teachers is the elegant pattern hiding inside it. To move a stack of n disks you first move the top n−1 disks out of the way, shift the biggest disk across, then move the n−1 disks back on top — the very definition of recursion. Because of that structure every puzzle has a known best solution, and the minimum number of moves is always 2ⁿ − 1: seven moves for three disks, fifteen for four, thirty-one for five, and a demanding one hundred and twenty-seven for seven. Since the optimum follows a clean formula, Tower of Hanoi is the perfect place to watch how a small change in size causes an exponential jump in effort.

How to Play

1Pick your challenge — choose 3 to 7 disks with the tabs. Every disk begins stacked on the left peg.
2Click a peg to pick up its top disk; the disk lifts to show it is in your hand.
3Click another peg to drop the disk there. Click the same peg again to set it back down.
4Rebuild the whole stack in size order on the right-hand goal peg to win.

A move is illegal — and the game will refuse it — whenever you try to:

  • move more than one disk in a single turn;
  • lift a disk that is not currently on top of its peg;
  • place a larger disk on top of a smaller disk;
  • leave a disk floating — every disk must rest on a peg or on a bigger disk.

Tower of Hanoi Tips & Strategy

The Tower of Hanoi always has a guaranteed solution, and with a little strategy you can reach it in the fewest possible moves. These techniques help you plan ahead instead of shuffling disks around at random.

  1. Think in smaller towers

    To move n disks, treat the top n−1 disks as a single sub-tower you must park on the spare peg first. Solving the puzzle in your head becomes far easier when you break it into three thoughts: move the small tower aside, move the big disk across, then move the small tower back on top.

  2. Follow the smallest-disk rhythm

    In an optimal solution the smallest disk moves on every other turn, always travelling the same direction around the three pegs. For an odd number of disks it cycles start → goal → spare; for an even number it cycles start → spare → goal. Keep that rhythm going and the in-between moves almost choose themselves.

  3. Never undo your last move

    Between the smallest-disk moves there is only ever one other legal move available, and sliding the small disk straight back where it just came from only wastes turns. If you make it a rule never to reverse the move you have just played, you stay on the shortest path to the finish.

  4. Aim for the magic number

    Before you start, work out the target of 2ⁿ − 1 moves and keep it in mind. That turns the puzzle into a personal challenge — can you finish a five-disk tower in exactly thirty-one moves? Matching or beating the minimum is far more rewarding than simply reaching the end by trial and error.

Understanding the Minimum Moves

The formula 2ⁿ − 1 is not a coincidence — it falls straight out of the recursive method. Moving n disks costs one move for the biggest disk plus twice the cost of moving the n−1 disks above it, which builds up as 1, 3, 7, 15, 31, 63 and 127 for one through seven disks. Each extra disk roughly doubles the work, which is why seven disks already demand well over a hundred perfect moves. The counter above the board always shows both your current move total and this minimum target, so you can see exactly how close to flawless your run has been.

There is a famous legend attached to the puzzle. Monks in an ancient temple were said to be moving sixty-four golden disks between three posts, and the world would end the moment they finished. At one move per second the minimum solution for sixty-four disks would take around 585 billion years — far longer than the current age of the universe — so there is no need to worry. It is a memorable way to feel just how quickly exponential growth outruns everyday intuition, and it explains why programmers reach for Tower of Hanoi whenever they want to demonstrate recursion.

Choosing Your Disk Count

Start small while the pattern is still new. Three disks solve in just seven moves and are perfect for learning the rhythm of the puzzle, while four and five disks add enough length that planning genuinely pays off. Six and seven disks are for players who want a proper mental workout — a seven-disk tower needs a flawless one hundred and twenty-seven moves, and a single careless drop can cost you a personal best. Your fewest-moves record is saved separately for each disk count, so you can chase a clean three-disk run and a hard-won seven-disk finish at the same time, then come back to lower each score move by move.

FAQ

Is Tower of Hanoi free to play?

Yes — Tower of Hanoi on vygam is completely free. There is no download and no sign-up; it plays instantly in your browser on phone, tablet or desktop.

How do you play Tower of Hanoi?

Move the whole stack of disks from the left peg to the right peg. Click a peg to lift its top disk, click another peg to drop it, and never place a larger disk on a smaller one.

What is the fewest number of moves to solve Tower of Hanoi?

The minimum is always 2ⁿ − 1 moves for n disks: 7 moves for 3 disks, 15 for 4, 31 for 5, 63 for 6 and 127 for 7. The move counter shows this target as you play.

Is Tower of Hanoi hard?

Three disks are gentle and quick, but the difficulty climbs fast because each extra disk roughly doubles the work. With a clear plan the puzzle is always solvable, and larger towers become a real test of patience and foresight.

Is Tower of Hanoi good for your brain?

Yes. Tower of Hanoi is widely used to teach recursion, planning and problem solving. Working out the order of moves exercises logical thinking and short-term memory, which is why it appears in classrooms and cognitive studies alike.

Games like Tower of Hanoi