Tower of Hanoi: How to Solve It
How to solve the Tower of Hanoi: the simple rule behind the fewest moves, the move counts for three to eight discs, and four peg and mixed start solutions.
The Tower of Hanoi is a stack of discs on a peg, largest at the bottom. You move it to another peg one disc at a time, and a disc may never sit on a smaller one. Tower of Hanoi has seven puzzles: towers of three to six discs, a tower that starts spread over the pegs, and two puzzles with a fourth peg. This guide explains the idea that solves all of them and gives the shortest solutions.
The rules
Tap a peg to lift its top disc and tap another peg to put it down. Only the top disc of a peg can move, and it can only go onto an empty peg or a bigger disc. The target is the peg on the right, marked with a star. The fewest possible moves earn three stars, and you get two stars if you are within about a quarter of that.
The one idea that solves it
Think about the biggest disc. It can only move when every other disc is out of its way, stacked on the third peg. So to move a tower of five discs from the left peg to the right peg you must:
- Move the four smaller discs from the left peg to the middle peg.
- Move the biggest disc to the right peg.
- Move the four smaller discs from the middle peg onto it.
Steps 1 and 3 are just smaller towers, solved the same way. That is why each extra disc doubles the work and adds one: 1 move for one disc, 3 for two, 7 for three, 15 for four, 31 for five and 63 for six. The general rule is 2 to the power of the number of discs, minus 1.
A rhythm you can follow
Thinking about towers inside towers is hard to keep in your head for long, so here is a rhythm that gives exactly the same moves:
- Odd moves: move the smallest disc one peg along, always round in the same direction. With an odd number of discs it goes to the right peg, then the middle, then the left, then the right again; with an even number it goes to the middle, then the right, then the left.
- Even moves: make the only other move there is, the one that doesn’t touch the smallest disc. There is always exactly one.
Three discs
The smallest disc is disc 1. For the three disc tower:
- Disc 1 to the right peg.
- Disc 2 to the middle peg.
- Disc 1 to the middle peg.
- Disc 3 to the right peg.
- Disc 1 to the left peg.
- Disc 2 to the right peg.
- Disc 1 to the right peg.
Seven moves. Four, five and six discs work the same way in 15, 31 and 63 moves.
Advertisement
A mixed start
In the fourth puzzle the five discs start spread out: discs 5 and 2 on the left peg, 4 and 1 in the middle, and 3 on the right. Use the same idea as before: the biggest disc, 5, is on the left and must reach the right peg, so first every smaller disc must be gathered on the middle peg. Gather them biggest first: disc 4 is already in the middle, so build 3, 2 and 1 on top of it, then move disc 5, then move the tower of four onto it. That takes 21 moves:
- Disc 1 to the left peg. 2. Disc 3 to the middle peg. 3. Disc 1 to the right peg. 4. Disc 2 to the middle peg. 5. Disc 1 to the middle peg. 6. Disc 5 to the right peg. 7. Disc 1 to the left peg. 8. Disc 2 to the right peg. 9. Disc 1 to the right peg. 10. Disc 3 to the left peg. 11. Disc 1 to the middle peg. 12. Disc 2 to the left peg. 13. Disc 1 to the left peg. 14. Disc 4 to the right peg. 15. Disc 1 to the right peg. 16. Disc 2 to the middle peg. 17. Disc 1 to the middle peg. 18. Disc 3 to the right peg. 19. Disc 1 to the left peg. 20. Disc 2 to the right peg. 21. Disc 1 to the right peg.
Four pegs
A fourth peg changes everything. You can park a few small discs on one spare peg and still have two pegs free for the rest. For five discs on four pegs, the shortest solution is 13 moves:
- Disc 1 to peg 2. 2. Disc 2 to peg 3. 3. Disc 3 to peg 4. 4. Disc 1 to peg 3. 5. Disc 4 to peg 2. 6. Disc 3 to peg 2. 7. Disc 5 to peg 4. 8. Disc 3 to peg 1. 9. Disc 4 to peg 4. 10. Disc 3 to peg 4. 11. Disc 1 to peg 1. 12. Disc 2 to peg 4. 13. Disc 1 to peg 4.
For eight discs on four pegs, use the same plan on a bigger scale. Move the top five discs to peg 2 using all four pegs (13 moves, as above). Then move the bottom three discs to peg 4 with only three pegs free, the classic way (7 moves). Then bring the five discs from peg 2 onto them, again with all four pegs (13 moves). That is 33 moves, the fewest possible, where three pegs would need 255.
Why it is called the Tower of Hanoi
The puzzle was invented by the French mathematician Édouard Lucas and sold as a toy in 1883. It came with a story about a temple where monks move a tower of 64 golden discs, and the world ends when they finish. At one move a second, 64 discs would take about 585 billion years, so there is no hurry.
Play it now
Every game is free in your browser, with nothing to download. See all the logic games.
Questions and answers
How many moves does the Tower of Hanoi take?
On three pegs, 2 to the power of the number of discs, minus 1: 7 moves for three discs, 15 for four, 31 for five and 63 for six.
What is the easiest way to solve it?
Move the smallest disc on every other turn, always one peg along in the same direction, and in between make the only other legal move.
How many moves does it take with four pegs?
Far fewer: 13 moves for five discs and 33 for eight. Park some small discs on a spare peg, move the rest, then bring the small ones back.
Where does the smallest disc go first?
With an odd number of discs, straight to the target peg; with an even number, to the middle peg.
Written by the DailyGameClub team from the rules as DailyGameClub plays them. Updated October 27, 2026. New to a word? See the glossary. Spotted a mistake? Tell us.