Back to articles
📁 Game Guides

Tower of Hanoi Solution for 3, 4 and 5 Discs: Every Move in a Table, Plus Two Rules to Remember

The Tower of Hanoi takes 7 moves with 3 discs, 15 with 4 and 31 with 5. Every move is listed in a table, and two simple rules let you play the shortest solution without looking. The tables come from this site's own solver and were played through in the game.

Play Tower of Hanoi online
✍️Flowerclaw⏱️ 10 min read
Tower of Hanoi Solution for 3, 4 and 5 Discs: Every Move in a Table, Plus Two Rules to Remember

The short answer: the fewest moves are 7 for 3 discs, 15 for 4 and 31 for 5. You only need two rules: on every odd move, move the smallest disc one peg along, always in the same direction; on every even move there is only one legal move that doesn't touch the smallest disc. Follow them and you will hit the minimum every time, no table needed. The full tables are below, so you can open Tower of Hanoi online and play along.

The move tables in this guide are generated by the same solver the game uses, and we played every move by hand: 3, 4 and 5 discs all finished in the minimum number of moves, with the game showing "Perfect! You used the minimum number of moves!".

The rules in 30 seconds

There are three pegs, and the left one holds a stack of discs of different sizes. Your goal is to move the whole stack to the right-hand peg, following just two rules:

  1. Only the top disc of a peg can move, one disc at a time.
  2. A larger disc can never sit on a smaller one.

Below, the pegs are called A (start), B (spare) and C (goal). They are pegs 1, 2 and 3 from left to right in the game, the same names the in-game How to Play guide uses.

The How to Play guide shown on your first visit: start peg on the left, spare peg in the middle, goal peg on the right

Two rules that replace the table

Rule 1: on odd moves (1st, 3rd, 5th…) always move the smallest disc, and always in the same direction.

  • With an odd number of discs (3, 5), the smallest disc cycles A → C → B → A.
  • With an even number of discs (4, 6), it cycles A → B → C → A.

So your very first move depends only on the disc count: with 3 or 5 discs the smallest disc goes straight to C; with 4 discs it goes to B first. Get the first move backwards and you can no longer finish in the minimum.

Rule 2: on even moves, leave the smallest disc alone. There is then exactly one legal move.

The smallest disc sits on one peg, so you can only move between the other two: take the smaller of their top discs and put it on the other peg (or onto the empty one). There is never a choice to make.

We checked both rules by program against the optimal solutions for 3, 4 and 5 discs: the smallest disc moves on every odd move and never changes direction.

3 discs: the 7-move solution

MoveDiscFrom → To
11 (smallest)A → C
22A → B
31 (smallest)C → B
43A → C
51 (smallest)B → A
62B → C
71 (smallest)A → C

After move 3 the two small discs are stacked on B, A holds only the largest disc and C is empty. That is the moment the whole puzzle builds towards: clear the small discs away, then move the big one. Move 4 puts disc 3 on C, and the last three moves stack the small discs back on top.

3 discs after move 3: both small discs are on the spare peg, so the largest disc can go straight to the goal

3 discs solved in 7 moves, recognised by the game as the minimum

4 discs: the 15-move solution

Four is even, so the smallest disc now cycles A → B → C.

MoveDiscFrom → To
11 (smallest)A → B
22A → C
31 (smallest)B → C
43A → B
51 (smallest)C → A
62C → B
71 (smallest)A → B
84A → C
91 (smallest)B → C
102B → A
111 (smallest)C → A
123B → C
131 (smallest)A → B
142A → C
151 (smallest)B → C

Move 8 is the key. The first seven moves simply carry a 3-disc tower from A to B, move 8 puts the largest disc, disc 4, on C, and the last seven moves carry the 3-disc tower from B onto C. This is what it looks like on a phone right after move 8:

4 discs on a phone after move 8: the largest disc is on the goal peg and the three smaller discs wait on the spare peg

5 discs: the 31-move solution

Five is odd again, so the smallest disc goes back to the A → C → B direction. Thirty-one moves sounds like a lot, but it is just "move 4 discs (15 moves) + move the largest disc (1 move) + move 4 discs again (15 moves)".

MoveDiscFrom → To
11 (smallest)A → C
22A → B
31 (smallest)C → B
43A → C
51 (smallest)B → A
62B → C
71 (smallest)A → C
84A → B
91 (smallest)C → B
102C → A
111 (smallest)B → A
123C → B
131 (smallest)A → C
142A → B
151 (smallest)C → B
165A → C
171 (smallest)B → A
182B → C
191 (smallest)A → C
203B → A
211 (smallest)C → B
222C → A
231 (smallest)B → A
244B → C
251 (smallest)A → C
262A → B
271 (smallest)C → B
283A → C
291 (smallest)B → A
302B → C
311 (smallest)A → C

Lost track halfway through? Press H (or tap Hint) and the game highlights the start and target pegs of the best next move. The screenshot below shows a hint after four moves with 5 discs. The highlighted pegs are exactly move 5 in the table: the smallest disc goes from B back to A.

5 discs after four moves with Hint pressed: the start and target pegs of the best move are highlighted

Why n discs need 2ⁿ−1 moves

To get n discs onto C, the largest disc has to move at some point, and it can only move once the n−1 discs above it are parked together on B. After the largest disc reaches C, those n−1 discs travel from B to C. So "moves for n discs = 2 × (moves for n−1 discs) + 1". Starting from 1 disc in 1 move, that gives 7 for 3 discs, 15 for 4, 31 for 5, and 2ⁿ−1 in general. For the full derivation and the recursive idea behind it, see Tower of Hanoi Minimum Moves: The 2ⁿ−1 Formula Explained.

DiscsMinimum moves
37
415
531
663
7127
8255
101023

Tips for practising in the game

  • Controls: tap or click a peg to lift its top disc, then tap the peg you want to drop it on. On a keyboard, use 1/2/3, or ← → plus Enter.
  • Mistakes are cheap: Z undoes a move and Y redoes it, so there is no need to start over.
  • Stuck? H shows the best next move. D (Show Solution) plays the rest of the optimal solution from your current position; tap any peg to stop it.
  • Disc counts unlock one by one: solve the current count to unlock the next, up to 10 discs. Your best moves and time for each count are saved in your browser.
  • Daily Challenge: 7 discs within a move limit (the optimum is 127). A good test once the two rules feel natural.

FAQ

Can I put the first disc on C with 4 discs? You can, but you will then need extra moves and can no longer finish in 15. With an even number of discs, the first move goes to B.

How do I know if I'm still on the optimal path? Watch Moves and Minimum at the top of the game. If they are equal when you finish, you found the perfect solution. Mid-game, compare your plan with the H hint.

Do the two rules work for 6 or 7 discs? Yes. Six is even, so the smallest disc cycles A → B → C; seven is odd, so it cycles A → C → B.


Try it now: open Tower of Hanoi, play 3 discs with the table, then close the table and solve 4 discs using only the two rules.

Share Article

Tower of Hanoi Solution: 3, 4 and 5 Discs Step by Step | Flowerclaw