J10M

Joue 10 minutes.

Tower of Hanoi

Move the tower disk by disk, never putting a big one on a small one. Ten levels, up to twelve disks and four pegs.

Ages 6 and up

Three pegs set in a board, a stack of disks sorted from largest to smallest, and a single rule: a disk never goes on top of a smaller one. Your mission fits in one sentence: move the whole tower to the peg on the right, one disk at a time. It sounds easy with three disks. With eight, you will understand why this puzzle has been famous for more than one hundred forty years.

Here the game comes in ten levels, split into two worlds. The first world is played with three pegs and grows the tower one disk at a time: three, four, five, six, seven, then eight. The second adds a fourth peg, and everything changes: the same tower can be moved two or three times faster. You finish with twelve disks on four pegs, and eighty-one moves as your only horizon.

The counter always shows two numbers: the moves you have played, and the theoretical minimum. That minimum is not an estimate; it is the result of an exact calculation, made by the game for each level. So you always know whether you are playing well, and how far you are straying from the shortest path.

If you are looking for a free Tower of Hanoi game to play online — to solve it for fun, to understand the famous minimum-moves formula, or to show a student what recursion looks like — this is a calm, step-by-step way to do it.

How to play

  1. Tap a peg. Its top disk lifts up and stays in the air, ready to go. It is the only disk you can move from that peg: the others are stuck underneath.
  2. Tap another peg. The disk slides over and drops onto it. If it is smaller than the disk it lands on — or if the peg is empty — the move goes through and the counter goes up by one.
  3. If the move is illegal, the disk shakes and goes back to its place: you tried to put a big disk on a smaller one. Nothing is lost, nothing is counted, you try again.
  4. Tap the same peg twice to put the disk back down without moving anything. No move is counted.

There is no drag and drop: you tap, then you place. That works just as well with a finger on a phone as with a mouse, and it avoids disks dropped in the wrong spot.

Four buttons help you along:

  • Undo goes back one move, as many times as you like, all the way to the start. The counter goes down with you.
  • Start over puts the whole tower back on the first peg and resets the counter to zero.
  • Hint shows the next move to play, with an arrow from one peg to another. It comes at a price, and the game warns you first: a level finished with a hint earns two stars at most.
  • Levels opens the map of the ten levels, with the stars you have earned on each.

On a keyboard, the number keys 1 to 4 pick the pegs, the left and right arrow keys move the cursor from one peg to the next, Enter lifts or drops, Backspace undoes the last move and Escape puts the lifted disk back down. So you can finish the whole game without a mouse, with a clear outline around the selected peg.

The rule that makes the whole game

A tower of disks does not move all at once. To put the largest disk on the target peg, that peg has to be empty, and all the smaller disks have to be somewhere else, stacked out of the way. In other words: before you move the big one, you first have to move the whole tower sitting on top of it.

That is the key to the puzzle, and the game tells you on the third level, in one sentence: for n disks, move the top n−1, then the big one, then the n−1 again. Once you have that idea, you can never get lost: every tower comes down to a smaller tower, all the way to a single disk, which you move without thinking.

This way of solving a problem by reducing it to a smaller version of itself has a name in computer science, recursion, and the Tower of Hanoi is the textbook example. You do not have to memorize anything: after five levels, you will have it in your fingers.

The minimum number of moves

With three pegs, the math is relentless: one more disk doubles the work, plus one move. Three disks take 7 moves, four take 15, five 31, six 63, seven 127, and eight 255. The formula fits in a few symbols: two to the power of n, minus one.

That growth is behind the legend attached to the game. The story goes that monks in a temple are moving a tower of sixty-four golden disks, and that the world will end when the tower is complete. At one move per second, without a single mistake, it would take them more than five hundred billion years. The world still has time.

The four-peg world

With one more peg, the puzzle becomes a different game. You have two places to set disks aside instead of one, and the best strategy is no longer to move everything as a single block, but to split the tower into two stacks.

The idea: you park a stack of small disks on a holding peg, using all four pegs; you move the rest of the tower with only three pegs, since the fourth is occupied; then you go back for the stack you set aside. The whole art lies in choosing the size of that stack.

The result is spectacular. Six disks take 63 moves with three pegs, and only 17 with four. Eight disks go from 255 to 33. Ten disks take 49 moves, and twelve take 81. The game works these numbers out itself, using the Frame–Stewart recurrence, which has been known since 2014 to give the true minimum for four pegs.

For twelve disks, one of the two best splits sets seven disks aside: you park them on a holding peg in 25 moves, move the five big ones with three pegs in 31 moves, then bring the seven small ones back in 25 moves. Twenty-five, plus thirty-one, plus twenty-five: eighty-one.

Stars and progress

Each level is won with one, two or three stars:

  • Three stars if you finish in the minimum number of moves, without a hint.
  • Two stars if you go over the minimum by 25% at most, rounded up. For a 17-move level, that leaves you up to 22 moves; for an 81-move level, up to 102.
  • One star as soon as the tower is rebuilt, however many moves it took.

One star is enough to unlock the next level: nobody stays stuck. But the level map keeps track of your best result, stars and number of moves, and nothing stops you from going back to a level you have already finished to grab the third star.

Your progress — stars, records and unlocked levels — is saved in your browser, with no account to create. If you switch devices or clear your browser data, the map starts again from ten blank levels.

Leaderboard

Every level you clear earns points, and your leaderboard score is the total of all your levels. Stars set the price: in the three-peg world, three stars earn 50 points, two earn 40 and one earns 30; the four-peg world pays double, so 100, 80 or 60 points. Clearing all ten levels in the minimum number of moves, without a hint, adds up to 700 points.

Each level counts once, for your best solution. Replaying a level for more stars raises your total; replaying it worse costs you nothing. The rules are the counter's rules: an undone move no longer counts, starting over resets everything, and a hint you have seen caps the level at 40 points in the first world and 80 in the second.

The leaderboard only keeps verified solutions: the server replays every move you made, undos, restarts and hints included, before it accepts the score. The first time you clear a level, the game asks for a nickname, and from then on your total is sent on its own without interrupting your game.

Tips for solving the Tower of Hanoi

  • Watch the smallest disk. With three pegs, in a game played in the fewest moves, it moves every other turn, and always in the same direction of rotation. If the number of disks is odd, it goes first to the target peg; if it is even, to the middle peg. Between two of its moves, there is only ever one other move that does not undo the previous one: you can play a whole level without ever hesitating.
  • Do not undo what you just did. Moving a disk back where it came from costs two moves for nothing. If you feel the urge, the previous move was often the wrong one: use Undo instead of going around in circles.
  • Think about the tower on top, not the disk underneath. Before moving the big disk, ask yourself where the stack covering it needs to go. Its destination is always the peg the big disk is not using.
  • With four pegs, count your stacks. A good split leaves roughly as much work for the parked stack as for the big disks. Park too few disks, and the three-peg part becomes huge; park too many, and you make a long trip twice.
  • Check your tower every two or three minutes. On the big levels, stop and look at where the three smallest disks are: if they are scattered over three different pegs, you have taken a detour.
  • A hint is not a defeat. Two stars with the solution understood beat ten wasted minutes. You can always replay the level cleanly afterward.

For more brain teasers that teach as you play, try Wolf, Goat and Cabbage or the Nim Game, or browse the educational games.

Frequently asked questions

What age is the game for? From five or six years old for the first levels: three disks, a single rule, and nothing to read. The eight-disk levels and the four-peg world will keep an adult very busy.

What is the minimum number of moves? With three pegs, two to the power of n, minus one: 7 moves for three disks, 255 for eight. With four pegs, the minimum is much lower — 17 moves for six disks, 81 for twelve — and the game shows it next to your counter, level by level.

Why does the fourth peg change everything? Because it gives you a second place to set disks aside. Instead of moving the whole tower as one block, you can park a stack of small disks, work calmly on the big ones, then come back for the stack. The number of moves no longer doubles with every disk you add.

Does undoing a move lower the counter? Yes. The counter shows the length of the path you have actually traveled from the start: if you undo, it goes down. So you can explore, make mistakes, go back, and still aim for three stars.

What does a hint cost? It caps the level at two stars, and the game tells you before showing it: you have to tap the button a second time to confirm. On the other hand, the number of hints does not matter: the first one has already cost everything. Starting the level over wipes the slate clean.

Is the move shown by the hint the best one? With three pegs, yes, always: the shortest path can be worked out exactly from any position. With four pegs, the hint follows the shortest path as long as you are on it, and brings you back to it as fast as possible if you have strayed.

Is there a leaderboard? Yes: it ranks players by the total points of the levels they have cleared, up to 700 if all ten are done in the minimum number of moves without a hint. The ten levels are the same for everyone, and you play them at your own pace.

Can I play entirely with a keyboard? Yes. The number keys 1 to 4 pick the pegs, the arrow keys move the cursor, Enter lifts and drops, Backspace undoes. The selected peg has a visible outline, and every move is announced to screen readers.

Where does this puzzle come from? From the French mathematician Édouard Lucas, who put it on sale in 1883 under a pen name, along with the legend of the temple and its sixty-four golden disks. Since then, it has been an example in every algorithms course in the world — and a patience game in every waiting room.

More educational games

Educational games
  • Plant Cell and Photosynthesis
    Spot the organelles on a real textbook diagram, then switch on photosynthesis and watch the leaf come to life.
  • Wolf, Goat and Cabbage
    The wolf eats the goat, the goat eats the cabbage: get everyone across. Twelve puzzles, and fails that make you laugh.
  • Electric Circuits
    Turn the wires, close the loop and light the bulbs: series, parallel and short circuits, in twenty-four levels.
  • Tangram
    Seven pieces, one shadow to fill: thirteen shapes and an album to complete.
  • Logic Gates
    Place the right gates, flip the switches and make the lamp follow the whole truth table.
  • Telling Time
    Set both hands to the time you're given, from o'clock times to the exact minute, PM times included.
  • Algebra Balance
    Take away, add, divide — but always on both sides. The scale stays level until x stands alone.
  • Making Change
    The customer pays too much: put the right coins in their hand, and as few as you can.