Solving the Tower of Hanoi in the fewest moves
How the puzzle works, why the minimum number of moves is a fixed formula, the recursive trick that cracks any size, and how to play it here with three to seven discs.

What you are looking at
Three pegs stand side by side. A stack of coloured discs sits on the left peg, each one smaller than the one below it. The goal is to move the entire stack to the right peg. You may only move one disc at a time, and a larger disc can never sit on top of a smaller one. That single rule is the whole puzzle.
You choose how many discs to work with, from three up to seven. Three is a warm-up that takes under a minute. Seven is a serious test of patience and memory.
Controls and how the board responds
Tap a peg to pick up its top disc. That peg is then marked as held. Tap a second peg to drop the disc there. If the target peg already has a smaller disc on top, the move is refused and you get a short message explaining why. Tap the same peg again to put the disc back and change your mind.
Three numbers sit above the board. Moves counts every disc you place. Fewest possible shows the theoretical minimum for the number of discs you chose. Moves left counts down from a limit that is a little above the minimum, so you have some room for mistakes but not unlimited room.
The disc selector below the board lets you switch between three and seven discs at any time. Changing it starts a fresh game. The New game button does the same thing without changing the count.
Why the minimum is always exact
The minimum number of moves for n discs is two to the power of n, minus one. Three discs need seven moves. Four need fifteen. Five need thirty-one. Seven need one hundred and twenty-seven. This is not a guess or an estimate. It is a mathematical proof, and no method will ever do it in fewer.
The proof is short. To move n discs, you must first move the top n minus one discs to the spare peg. That is the same puzzle with one fewer disc. Then you move the bottom disc across. Then you move the n minus one discs again, from the spare peg to the target. Each of those sub-problems costs the same, and the bottom disc adds one move. The total comes to twice the previous answer plus one, which gives the formula.
The recursive trick, step by step
Think about four discs on three pegs, named left, middle, and right. The job is to get all four from left to right.
First, move the top three discs from left to middle. Ignore the bottom disc while you do this. The bottom disc is too large to get in the way of anything, so it may as well not exist. Moving three discs is a puzzle you already know how to solve.
Second, move disc four from left to right. It is now alone, so this is one simple move.
Third, move the three discs from middle to right. Again, the same smaller puzzle.
That is the entire method. Each step is either one move or a smaller copy of the same puzzle. When you reach one disc, the answer is obvious. When you reach two, you move the small one aside, move the big one, then put the small one on top. Everything larger is just more nesting of the same idea.
The smallest disc rule
There is a shortcut that saves a lot of thinking. On every odd-numbered move, the smallest disc moves. On every even-numbered move, one of the other discs moves. And the smallest disc always travels in the same direction around the three pegs.
For an odd number of discs, the smallest disc cycles left, middle, right, left, middle, right. For an even number, it goes the other way: left, right, middle, left, right, middle. Once you know which direction applies, half the moves are decided for you. On the even-numbered moves, there is only one legal move that does not involve the smallest disc, so the entire puzzle becomes mechanical.
This pattern holds for any number of discs. It is why experienced players can solve the puzzle at speed without pausing to think.
Scoring and the move limit
The game tracks your move count against the mathematical minimum. If you finish inside the move limit, the board tells you whether you hit the perfect score or how many extra moves you used.
The limit is set at the minimum plus a small allowance. For three discs the minimum is seven moves, so you have a few more on top before the game calls time. For seven discs the minimum is one hundred and twenty-seven, and the budget is larger in proportion.
When you run out of moves, the game ends with a hint about the recursive method. Your best score for each disc count is saved in your browser, so you can try to match the perfect figure across separate sessions.
Mistakes that waste moves
- Moving a disc to the spare peg and then immediately moving it back. Two moves spent for no progress. Pick up a disc only when you know where it belongs.
- Forgetting which sub-problem you are in. With five or more discs, you will be three or four levels deep in the recursion. Lose track and you start shuffling discs at random, which eats through the budget fast.
- Trying to solve it from the big disc up. The puzzle works top-down, not bottom-up. Clear the small discs first, then move the big one, then bring the small discs back.
- Ignoring the smallest-disc pattern. If you do not follow it, you will make legal moves that are correct in isolation but lead nowhere. The pattern is a rail that keeps you on the shortest path.
- Starting on seven discs before mastering three. Seven discs is the same logic, but you have to hold it in your head for one hundred and twenty-seven moves. Three discs teaches the pattern in seven moves, and four in fifteen. Build the habit before adding size.
Working through three discs
Label the pegs A, B, and C. Discs are numbered one (smallest) to three (biggest). All start on peg A.
Move one: disc one goes to C. Move two: disc two goes to B. Move three: disc one goes from C to B, on top of disc two. Move four: disc three goes to C. Move five: disc one goes from B to A. Move six: disc two goes from B to C. Move seven: disc one goes from A to C.
Every disc is now on peg C, in order. That took exactly seven moves, which is two to the power of three minus one. No shortcut exists. If you follow the smallest-disc rule, the moves fall out in exactly this order without any choices to make.
Choosing your difficulty
Three discs is a puzzle you can solve in your head before touching the board. Use it to learn the pattern. Four discs takes fifteen moves and still fits comfortably in short-term memory. Five discs, at thirty-one moves, is where most people start needing the smallest-disc rule to stay on track.
Six discs needs sixty-three moves. Seven needs one hundred and twenty-seven. At these sizes the puzzle is not harder to understand, but it is harder to execute. The recursion is the same; you simply have more layers of it to hold in your mind. If you can do seven in the minimum, you have genuinely internalised the algorithm.
Everything stays on your own machine
The puzzle runs entirely in your browser. No moves are sent anywhere. There is no server keeping track of your score, your time, or how many attempts you have made. Your best result for each disc count is saved in local storage on your device, and it stays there until you clear your browser data. You can prove it by loading the page, going offline, and playing a full game. Everything still works because there was never anything on the other end. Close the tab and nothing is left behind except that one saved score.
