Tower of Hanoiplay the classic disk puzzle online, free
Move the whole stack from the first peg to the last, one disk at a time, never a larger disk onto a smaller one. Pick 3 to 8 disks, tap or drag to move, with undo, hints, and an optimal-move target — no download, no sign-up.
Moves
0/7
Time
0:00
Best
—
Choose your disks
Solve 3 disks in as few as 7 moves.
Move the whole stack to the right peg — never a larger disk on a smaller one
What is the Tower of Hanoi
One rule, three pegs, an endless test of order
The Tower of Hanoi is a mathematical puzzle from 1883. A stack of graduated disks starts on the left of three pegs and must be rebuilt on the right, moving one disk at a time and never dropping a larger disk on a smaller one. It looks trivial with three disks and becomes a genuine planning problem by eight — and it is the textbook example of recursion in computer science.
- 3 to 8 disks
- Start with three disks and a seven-move solution, or push to eight disks and 255 moves. Your best moves and times are tracked separately for every size.
- Plays in your browser
- No download, no install, no plugins. playtowerofhanoi.com loads a fresh puzzle the moment the page opens, on desktop and mobile.
- Undo and a real hint
- Unlimited one-tap undo back to the start, plus a hint that flashes the optimal next move from wherever you are — not just from the opening position.
- Progress saved locally
- Fewest moves, fastest time, puzzles solved, and perfect optimal solves for each disk count are stored on your device — never on a server.
How to play
How to play the Tower of Hanoi
Move the whole stack from the left peg to the right peg. One disk per move, only the top disk of a peg, and never a larger disk onto a smaller one.
- 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
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
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
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.
Tips for an optimal solve
- 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.
FAQ
The Tower of Hanoi, answered
Straight answers about the free Tower of Hanoi puzzle you can play online in your browser.
What is the Tower of Hanoi?
The Tower of Hanoi is a single-player logic puzzle invented by the French mathematician Édouard Lucas in 1883. You start with a stack of graduated disks on one of three pegs and must rebuild the whole stack on another peg, moving one disk at a time and never placing a larger disk on a smaller one. It is a classic teaching example of recursion in mathematics and computer science.
How do you play the Tower of Hanoi?
Move the entire stack of disks from the left peg to the right peg. You may move only the top disk of a peg, only one disk per move, and you may never set a larger disk on top of a smaller one. Tap a peg to lift its top disk, then tap the destination peg to drop it. The puzzle is solved when every disk is stacked in order on the right peg.
Is the Tower of Hanoi free to play online?
Yes. playtowerofhanoi.com is completely free and runs entirely in your browser. There is nothing to buy, download, or install, and there are no interruptive video ads, premium tiers, or paywalls. Open the page and a puzzle is ready.
Do I need to download an app or create an account?
No. The puzzle is the website — a 100% browser-based build with no app-store download and no sign-up. Your best moves and times are saved locally in your browser, so there is no login to manage.
What is the minimum number of moves for the Tower of Hanoi?
For n disks the minimum is 2 to the power of n, minus one. That is 7 moves for 3 disks, 15 for 4, 31 for 5, 63 for 6, 127 for 7, and 255 for 8. No solution can ever do it in fewer moves, and exactly one optimal sequence exists for each starting position. The game shows your move count against this target as you play.
How many disks can I play with?
You can choose any number of disks from 3 to 8. Three disks solve in 7 moves and take under a minute; eight disks need at least 255 moves and are a serious test of the pattern. Your stats are tracked separately for each disk count.
Which peg do I have to finish on?
This version asks you to move the stack to the right-hand peg, which is the standard statement of the puzzle. The left peg is the start and the middle peg is the spare you use for staging. The hint and move target are both calculated toward the right peg.
What is the trick to solving the Tower of Hanoi?
Two moves repeated forever. First, never move the smallest disk twice in a row. Second, on every other turn move the smallest disk one peg in a single fixed direction around the three pegs; on the turns in between, make the only other move that is legal. Keep going and the tower rebuilds itself in the optimal number of moves.
Why is the Tower of Hanoi used to teach recursion?
Because the solution is defined in terms of itself. To move n disks, you move n − 1 disks out of the way, move one disk, then move the n − 1 disks back — and each of those is the same problem with a smaller stack. That structure maps directly onto a recursive function that calls itself twice with n − 1, which is why it appears in almost every programming course.
Is every Tower of Hanoi puzzle solvable?
Yes. Unlike shuffled card games, the Tower of Hanoi always has a solution from the standard starting position, and that solution is unique if you want the fewest moves. If you get tangled, undo back to a position you understand — you can never reach a truly stuck state.