Skip to content

Tower of Hanoi with 7 Disks

The shortest solution is 127 moves. Play them on the board, or read every one in the list under it.

Optimal solution

127moves2⁷ − 1

First move
Disk 1, A → C
At one move a second
2 minutes
Difficulty
Hard

7 disks on tower A. 127 moves to go.Step 0 of 127

Every move of the 7-disk solution
MoveDiskFromTo
11AC
22AB
31CB
43AC
51BA
62BC
71AC
84AB
91CB
102CA
111BA
123CB
131AC
142AB
151CB
165AC
171BA
182BC
191AC
203BA
211CB
222CA
231BA
244BC
251AC
262AB
271CB
283AC
291BA
302BC
311AC
326AB
331CB
342CA
351BA
363CB
371AC
382AB
391CB
404CA
411BA
422BC
431AC
443BA
451CB
462CA
471BA
485CB
491AC
502AB
511CB
523AC
531BA
542BC
551AC
564AB
571CB
582CA
591BA
603CB
611AC
622AB
631CB
647AC
651BA
662BC
671AC
683BA
691CB
702CA
711BA
724BC
731AC
742AB
751CB
763AC
771BA
782BC
791AC
805BA
811CB
822CA
831BA
843CB
851AC
862AB
871CB
884CA
891BA
902BC
911AC
923BA
931CB
942CA
951BA
966BC
971AC
982AB
991CB
1003AC
1011BA
1022BC
1031AC
1044AB
1051CB
1062CA
1071BA
1083CB
1091AC
1102AB
1111CB
1125AC
1131BA
1142BC
1151AC
1163BA
1171CB
1182CA
1191BA
1204BC
1211AC
1222AB
1231CB
1243AC
1251BA
1262BC
1271AC
On this page
  1. The solution
  2. The shape of the solution
  3. Which disk moves when
  4. The smallest disk's circuit
  5. About the 7-disk puzzle
  6. Other sizes
  7. Frequently asked questions

The shape of the solution

There are never 127 separate moves to remember — only three stages:

  1. Moves 1 to 63: build a tower of 6 disks on B.
  2. Move 64: disk 7 crosses to C — the only time it moves.
  3. Moves 65 to 127: rebuild the 6-disk tower on top of it.

Stages 1 and 3 are each the 6-disk solution, with two towers' names swapped.

Which disk moves when

Disk 1 makes half of all the moves — 64 of them, on every odd-numbered move. Each larger disk moves half as often as the one above it, which is the binary counter hiding inside the puzzle: the disk that moves is one more than the number of times you can halve the move number and still get a whole number. Move 6 halves once, to 3, so move 6 is disk 2. There is more on that in Tower of Hanoi and binary.

DiskMovesFirst moves onThen every
164move 12 moves
232move 24 moves
316move 48 moves
48move 816 moves
54move 1632 moves
62move 3264 moves
71move 64

The smallest disk's circuit

With 7 disks — an odd number — disk 1 travels A → C → B → A for the whole game, never reversing. Every move in between is the only legal move that leaves disk 1 alone. Those two rules alone reproduce the list above move for move; the iterative solution explains why, and strategies turns it into something to play by.

About the 7-disk puzzle

A hundred and twenty-seven moves, and a number with more history attached than any other on this site. 127 is 2⁷ − 1, a Mersenne prime. Use 127 itself as the exponent and the result, 2¹²⁷ − 1, is prime too — a thirty-nine-digit number that Édouard Lucas proved prime in 1876, working by hand with a method he invented for the purpose. It stayed the largest known prime for seventy-five years.

Seven years after that proof, Lucas published this puzzle under a false name. So the seven-disk game is the one place where the move count of his puzzle and the most famous result of his career meet: play this solution and you are counting out the exponent of his prime. The history of the puzzle has the rest of the story.

As a game, seven disks is Hard on this board and about two minutes at a steady move a second. Seven is odd, so disk 1 goes to C first and circles A, C, B for all sixty-four of its moves.

Other sizes

Frequently asked questions

How many moves does it take to solve Tower of Hanoi with 7 disks?

127 moves is the minimum: 2⁷ − 1 = 127. No solution with fewer moves exists, and any solution with more has wasted some.

What is the first move in 7-disk Tower of Hanoi?

Move disk 1, the smallest, from tower A to tower C. With an odd number of disks the smallest disk travels A → C → B → A for the whole game, so its first stop is C. Sending it to B first still lets you finish, but it costs one extra move.

How long does 7-disk Tower of Hanoi take to solve?

A perfect game is 127 moves, which at one move a second is 2 minutes and at three moves a second — about as fast as anyone plays by hand — 42 seconds.

Is 127 a prime number?

Yes. 127 is 2⁷ − 1, a Mersenne prime, and it leads to a second one: 2¹²⁷ − 1 is also prime. Édouard Lucas, the mathematician who later invented the Tower of Hanoi, proved that in 1876, and it stayed the largest known prime until 1951.