Tower of Hanoi
Move the whole stack from the left peg to the right peg, one disc at a time, never putting a larger disc on a smaller one.
Tower of Hanoi is a puzzle where you move a stack of discs from one peg to another, one disc at a time, and never place a larger disc on a smaller one. You can play this tower of hanoi game online free in your browser, with no download or sign-up. All discs start on the left peg, and you win by moving them all to the right peg, peg 3.
You can choose from 3 to 8 discs. The tool counts your moves and compares them with the minimum possible for that disc count. You can undo moves, ask for a hint, or watch an animated solution. If you are new to the puzzle, start with 3 discs. The shortest solution takes 7 moves.
How to play tower of hanoi online
- Open the Discs menu and choose a number from 3 to 8. The default is 3. Changing it starts a new game.
- To move a disc by clicking, click a peg to lift its top disc. The peg is outlined. Then click another peg to drop the disc there. Clicking the same peg puts the disc back.
- To move a disc by dragging, press on a top disc, drag it over a peg and release. Releasing it on its own peg snaps it back.
- To use the keyboard, press 1, 2 or 3 to lift a disc from that peg or drop it onto that peg. You can also press Tab to reach a peg, use Arrow Left and Arrow Right to move between pegs, and press Enter or Space.
- Press Undo (or U, or Ctrl/Cmd+Z) to take back your last move.
- Press Hint (or H) to see the next move of a shortest solution from your current position.
- Press Solve to watch the optimal solution play out. Press Stop to take control again at the current position.
- When all discs are on peg 3, a “Solved!” dialog shows your moves and the minimum.
Press New game (or N) to start over. Press Fullscreen (or F) to enlarge the pegs to the screen height. Press Esc to close a dialog.
What are the tower of hanoi rules?
You may move only the top disc of a peg, and only one disc per move. A move takes the top disc from one peg and places it on another peg. You may never place a larger disc on a smaller one.
What are the tower of hanoi game rules in this tool?
The three pegs are numbered 1, 2 and 3 from left to right. All discs start stacked on peg 1, with the largest at the bottom. Peg 3, on the right, is the goal, and peg 2 is the spare. The game is won when every disc is on peg 3, in the same stack order.
An illegal move is refused. The status line says “Not allowed: a larger disc cannot go on a smaller one.”, the target peg flashes red, and the move is not counted.
Tower of hanoi explained: how many moves is the minimum?
The minimum number of moves for n discs is 2^n − 1. For 3, 4, 5, 6, 7 and 8 discs, that is 7, 15, 31, 63, 127 and 255 moves. The count roughly doubles with each extra disc.
The reason is that the bottom disc can move only after all the others are off it. To move n discs, you first move the n − 1 smaller discs out of the way, move the bottom disc once, and then move the n − 1 discs back on top. That gives a total of 2 × (moves for n − 1) + 1.
What is the tower of hanoi strategy?
Solve the puzzle in parts. To move discs 1 to k to a peg, first move discs 1 to k − 1 to the spare peg, then move disc k, then move discs 1 to k − 1 on top of it. Each smaller stack is solved the same way.
With an odd number of discs, the first move of the smallest disc goes to the goal peg (peg 3). With an even number of discs, it goes to the middle peg (peg 2). For 3 discs, the 7-move solution is 1→3, 1→2, 3→2, 1→3, 2→1, 2→3, 1→3.
What are some tower of hanoi tips for beginners?
Move the smallest disc every other turn. In the shortest solution, the smallest disc moves on every second move, always around the pegs in the same direction, and the move in between is the only legal move that does not use the smallest disc.
Use Undo freely, since it only takes back moves and does not hurt your progress. Use Hint when you are stuck. Hints do not stop a game from counting for your Best.
Frequently asked questions
Is the tower of hanoi game free, and do I need to sign up?
Yes, it is free to play in your browser. The game saves progress only on this device, and nothing is sent anywhere.
Can I play tower of hanoi on a phone?
Yes. The pegs scale to the width of the screen, and 8 discs fit on a 320 px or 375 px wide phone without sideways scrolling. You can tap pegs or drag discs with your finger.
Is my tower of hanoi game saved?
Yes. The game in progress, the number of discs and your best move count for each disc count are saved in your browser. Reloading the page returns you to the same position.
Is there a tower of hanoi trick to solve it faster?
There is no shortcut that lowers the minimum. The useful pattern is the one in the strategy section: move the smallest disc every other turn and solve each smaller stack the same way.
What is the tower of hanoi pattern for the number of moves?
The minimum is always 2^n − 1 for n discs. Each disc count from 3 to 8 gives 7, 15, 31, 63, 127 or 255 moves.
Can I play with more than 8 discs or more than 3 pegs?
No. The game supports 3 to 8 discs and always uses 3 pegs. It has no timer, so you can take as long as you need.
More games
- 2048: Try it when you want a sliding number puzzle.
- Minesweeper: Pick it for another puzzle that rewards careful thinking.
- Memory Game: Use it when you want a quick game of matching pairs.
- Mancala: Play it for a classic board game of sowing and capturing seeds.
- Reversi: Choose it if you enjoy a two-player strategy board game.
- Spider Solitaire: Try it for a card game you can play on your own.
- Peg Solitaire: jump pegs over each other until only one is left on the board.
- Water Sort Puzzle: pour coloured layers between tubes until each tube holds one colour.