Back to Game

How to Play Tower of Hanoi

The complete guide — from basic rules to the recursive algorithm.

The Three Rules

One Disk at a Time

You may only pick up and move the top disk of any peg per turn.

Smaller on Larger Only

A disk can only be placed on a peg that is empty or has a larger disk on top.

Move All to Peg C

The goal is to move the entire stack from Peg A to Peg C, using Peg B as auxiliary.

Minimum Moves Formula: 2ⁿ − 1

For n disks, the minimum number of moves is always 2ⁿ − 1. This is proven to be optimal — no solution exists with fewer moves.

Disks Difficulty Min. Moves
3 Easy 7
4 Medium 15
5 Hard 31
6 Expert 63
7 Master 127
8 Legend 255

The Recursive Solution

The Tower of Hanoi has a beautifully simple recursive algorithm. To move n disks from peg A to peg C using peg B:

  1. Move the top n−1 disks from A to B (using C as helper)
  2. Move the largest disk from A directly to C
  3. Move the n−1 disks from B to C (using A as helper)
hanoi(n, from, to, via):
if n == 0: return
hanoi(n-1, from, via, to)
move disk: from → to
hanoi(n-1, via, to, from)

The Auto-Solve button on the game page executes exactly this algorithm — watch it step by step to see recursion in action!

Strategy Tips

Think one level up. Your immediate goal is usually to get the largest unplaced disk to its final position.

For 3 disks, memorise the 7-step sequence: A→C, A→B, C→B, A→C, B→A, B→C, A→C.

Use Undo freely — there's no penalty. It's better to think again than to make extra moves.

Watch Auto-Solve on 3 disks first. The pattern becomes clear and scales to any number of disks.

Use keyboard shortcuts: 1/2/3 to select pegs, ⌘Z to undo — much faster than clicking.

Tower of Hanoi FAQ

What are the rules of Tower of Hanoi?

You can move only one disk at a time, only move the top disk of any stack, and never place a larger disk on top of a smaller disk.

What is the minimum number of moves in Tower of Hanoi?

The minimum number of moves is 2 to the power of n minus 1, where n is the number of disks. For example, 3 disks need 7 moves and 8 disks need 255 moves.

What is the recursive solution to Tower of Hanoi?

To move n disks from one peg to another, move n minus 1 disks to the helper peg, move the largest disk to the destination peg, then move the n minus 1 disks onto the largest disk.

What is the best strategy for Tower of Hanoi?

The best strategy is to think recursively, free the largest remaining disk, and always work toward its final position before rebuilding the smaller stack on top.

Play Now