Guide

How to Play the Tower of Hanoi

The Tower of Hanoi is a game of order and planning. Move the whole stack from the left peg to the right, one disk at a time, never a larger disk onto a smaller one — and learn the recursive method that always finds the shortest solution.

Play Tower of Hanoi

The objective

Rebuild the whole stack on the right peg

The Tower of Hanoi uses three pegs and a set of disks of different sizes. Every disk starts on the left peg, largest on the bottom, smallest on top. You win when the entire stack has been moved, in the same order, onto the right-hand peg.

There is no timer forcing your hand and no luck involved. The whole challenge is the order you move disks in, because a single rule — never a larger disk on a smaller one — means the tower can only be moved by shuttling sub-stacks between all three pegs.

The puzzle is free, runs in the browser, and needs no account. Open the board when you want to play; use this guide for the rules, the controls, and the method that always finds the shortest solution.

The setup

Three pegs, one pyramid, 3 to 8 disks

Pick a disk count on the start screen. Three disks make a quick puzzle you can solve in seven moves; eight disks need at least 255 moves and real planning. Whatever you choose, the disks begin as a neat pyramid on the left peg and the other two pegs start empty.

The middle peg is not decorative — it is the staging area. Because you can never move more than one disk, everything sitting above a disk you want to move has to be parked somewhere first, and the spare peg is where it goes.

Controls

Tap, drag, or use the keyboard

Every method moves the same disks. Pick whichever fits the device in your hand.

  • Everywhere

    Tap to move

    Tap or click a peg to lift its top disk — the disk rises and the peg highlights. Tap a second peg to drop it there. Tap the same peg again to put the disk back and pick another. It works the same with a mouse or a finger.

  • Desktop & touch

    Drag and drop

    Prefer to drag? Press on the top disk of any peg and pull it onto another peg, then release. Illegal drops bounce back with a short sound and no move is spent.

  • Desktop

    Keyboard

    Press 1, 2, or 3 to pick up from that peg, then press another number to drop. U undoes the last move, H shows the optimal next move, R restarts the puzzle, N starts a new one, and M mutes the sound. Every on-screen control has a visible focus ring.

The method

Four steps from setup to solved

Read the board, think in sub-towers, and every position becomes a smaller version of the same puzzle.

  1. 1

    Read the setup

    Three pegs stand side by side. Every disk starts on the left peg, stacked largest at the bottom to smallest at the top — a neat pyramid. The middle and right pegs are empty. Choose how many disks you want, from three for a quick warm-up to eight for a real workout.

  2. 2

    Move one disk at a time

    A move takes the single top disk off one peg and drops it on another. You can never pick up a disk from the middle of a stack, and you can never place a larger disk on top of a smaller one. Tap a peg to lift its top disk, then tap the peg you want to move it to.

  3. 3

    Use the middle peg as a staging area

    You cannot carry the whole tower across in one go, so the spare peg is where sub-towers wait. Getting the biggest disk to the right peg means first parking everything above it on the middle peg, then rebuilding on top once the big disk is home.

  4. 4

    Finish on the right peg

    The puzzle is solved the moment the entire stack sits in order on the right-hand peg. The move counter shows how you did against the theoretical best of 2 to the power of n, minus one — 7 moves for three disks, 15 for four, 255 for eight.

Rules

Every rule that decides a move

  • The objective

    Move the complete stack of disks from the left peg to the right peg. The puzzle is won when every disk is back in order — largest on the bottom, smallest on top — on the right-hand peg.

  • One disk per move

    Each move transfers exactly one disk: the topmost disk of a peg. You cannot slide two disks together or pull a disk out from under another.

  • Never larger on smaller

    A disk may only be placed on an empty peg or on top of a disk larger than itself. This single restriction is what makes the puzzle hard — and what forces the recursive back-and-forth solution.

  • The optimal move count

    The fewest moves that can ever solve n disks is 2 to the power of n, minus one. That is 7 for three disks, 15 for four, 31 for five, and 255 for eight. The game tracks your moves against this target as you play.

  • Undo and restart

    Every move can be undone, all the way back to the start, so a wrong turn is never fatal. Restart rebuilds the tower on the left peg with the same disk count whenever you want a clean run.

Recursion & maths

Why 2ⁿ − 1 is the shortest possible

To move the largest disk, every smaller disk must first be stacked on the spare peg — that is a full solve of n − 1 disks. Then the big disk moves once, then the n − 1 stack moves again. So the shortest solution for n disks is twice the shortest for n − 1, plus one: 2ⁿ − 1.

  1. 01 · Why the puzzle always works

    The recursive idea

    To move n disks to the target peg, first move the top n − 1 disks to the spare peg, then move the single largest disk to the target, then move those n − 1 disks from the spare peg onto it. Each of those sub-moves is the same puzzle with one fewer disk, all the way down to a single disk you just place.

  2. 02 · For playing by hand

    The three-move cycle

    There is a purely mechanical version. Never move the same disk twice in a row. On odd turns, move the smallest disk one peg in a fixed direction (for an odd number of disks, toward the target; for an even number, away from it, wrapping around). On even turns, make the only legal move that does not involve the smallest disk. Repeat until solved.

Minimum moves by disk count
DisksMinimum moves (2ⁿ − 1)
37
415
531
663
7127
8255

Common mistakes

Why solvable puzzles get tangled

  • Moving the smallest disk twice in a row

    It always feels available, so it is tempting to keep shuffling it. But two moves of the same disk in a row waste a turn and break the rhythm of the solution. Alternate: small disk, other move, small disk, other move.

  • Letting the smallest disk change direction

    The optimal solution moves the smallest disk in a single loop around the pegs. The moment you send it back the way it came, you are unwinding progress. Commit to a direction on move one.

  • Burying a disk you will need

    Dropping a mid-size disk onto the target peg too early can block the larger disk that has to land there first. Before a move, ask whether it helps the next-largest disk reach its home.

  • Playing without a sub-goal

    Random legal moves rarely converge. Always be working toward a concrete sub-tower — “clear the top four onto the spare peg” — and switch goals only when the current one is done.

Strategy habits

Tips for an optimal solve

A summary — the full strategy page walks through the recursive and by-hand methods in depth.

  • The smallest disk moves on every other turn — turns 1, 3, 5 and so on. If you just moved it, your next move must be somewhere else.
  • The smallest disk always travels in one consistent direction around the three pegs. Pick that direction at the start and never reverse it.
  • On the turns when you do not touch the smallest disk, there is only ever one legal move. Find it and take it.
  • For an odd number of disks, send the smallest disk toward the target peg first. For an even number, send it toward the spare peg first.
  • Think in sub-towers: “get the top three onto the middle peg” is a goal you can actually plan, unlike “solve eight disks”.
  • If you lose the thread, use undo to step back to a position you understand rather than guessing forward.
  • Use the hint sparingly. Seeing one optimal move is enough to re-orient; leaning on it every turn stops you learning the pattern.

Where you can play

Same puzzle on phone and desktop

playtowerofhanoi.com runs in any modern browser with no app to install. Progress stays on the device you played on.

  • Desktop browsers

    Chrome, Edge, Firefox, and Safari all run the puzzle with no plugin. Click a peg to lift and drop, drag a disk with the mouse, or use the number keys with U for undo and H for a hint.

  • Phones and tablets

    The layout is touch-first. Tap a peg to pick up its top disk and tap another peg to move it. All three pegs and up to eight disks stay on one screen in portrait, and restart is instant.

  • Progress on this device

    Fewest moves, fastest time, puzzles solved, and perfect (optimal, hint-free) solves for each disk count from three to eight live in local browser storage. They stay until you reset them or clear site data, and they do not sync between devices.

Still stuck on a rule? Read the Tower of Hanoi FAQ or jump in and play.

Play Tower of Hanoi free