By Knexio · Updated May 2026
Classic mathematical puzzle — move all disks to tower C!
The Tower of Hanoi is a classic mathematical puzzle invented by French mathematician Édouard Lucas in 1883. It consists of three rods and a number of disks of different sizes which can slide onto any rod. The goal is to move the entire stack from tower A to tower C, moving only one disk at a time and never placing a larger disk on a smaller one. The puzzle is used to teach recursion in computer science courses worldwide. If you moved one disk per second, 64 disks would take roughly 585 billion years to complete.
Move only one disk at a time. Only the top disk of a tower can be moved. Never place a larger disk on top of a smaller disk. The goal is to move all the disks from tower A to tower C. Click a tower to select it (it will highlight blue), then click a destination tower to move the top disk there. Click the same tower again to deselect. You win when all disks are stacked on tower C in the correct order.
Think several moves ahead before acting. Use tower B as temporary storage strategically. The largest disk should move only once directly to tower C. Smaller disks move far more frequently than larger ones. The cleanest way to solve is to think in phases: move the smaller stack aside, shift the largest disk once, then rebuild the smaller stack on top. If you try to improvise too much, you end up backtracking and undoing your own progress. Every move is part of a repeating structure, and once you understand that structure, the board stops feeling random. You are not guessing; you are following a recursive plan one step at a time.
The minimum moves required is 2n − 1 (where n = number of disks). 3 disks → 7 moves; 4 disks → 15 moves; 5 disks → 31 moves; 6 disks → 63 moves. The formula works because each larger disk can only move after the smaller stack is cleared away, so the puzzle doubles the work at each step and adds one final move for the biggest disk.
Click a tower to select it (it highlights in blue). Then click the destination tower to move the top disk there. Click the same tower again to deselect.
It resets the puzzle and demonstrates the optimal recursive solution step by step, so you can watch and learn the algorithm.
The formula is 2n − 1. For 4 disks that's 2⁴ − 1 = 15 moves, and for 6 disks it is 63 moves. That formula works because each larger disk can only move after the smaller stack is cleared away, so the puzzle doubles the work at each step and adds one final move for the biggest disk.
Yes — completely free, no download or login required. It runs entirely in your browser on any device.