Tower of Hanoi Online — Free Puzzle Game & Auto Solver

Play manually, undo mistakes, save your best score, or watch Auto-Solve animate the minimum-move solution. Private by design—everything runs locally in your browser.

Board

Tap a peg to pick up the top disk, then tap another peg to place it.
Choose a peg to pick up a disk. Only smaller disks can sit on larger ones.

Everything runs locally in your browser — no uploads, no accounts.

Controls & Stats

Moves0 Optimal0 Disks3 Your best

Tip: You can click the canvas anywhere—I'll pick the nearest peg.

Shortcuts: 1/2/3 pegs, N new, S solve, P pause, U undo.

Progress Badges

Advertisement

How to Play Tower of Hanoi

  1. Move all disks from Peg A to Peg C.
  2. Move only one disk at a time.
  3. Only the top disk on a peg can move.
  4. Never place a larger disk on a smaller disk.

Minimum Moves Formula

The minimum number of moves is 2n − 1, where n is the number of disks.

Tower of Hanoi minimum moves
DisksMinimum movesDifficulty
37Easy
415Beginner
531Medium
663Hard
7127Expert
8255Challenge
Step-by-Step Tower of Hanoi Solution

Select the number of disks, then use Auto-Solve to see every move in the optimal solution.

    About Towers of Hanoi

    Release Updates

    v1.1 (February 9, 2026)

    • Added Best Score tracking per disk count (saved locally in your browser).
    • Added Undo / Redo history to support safer experimentation.
    • Added a Run Summary after wins with moves, optimal gap, and accuracy plus a one-click next-disk action.
    • Added persistent Progress Badges for key milestones.
    • Added keyboard shortcuts for faster play: 1/2/3 pegs, N, S, P, U.

    Play manually with simple tap/tap moves, or watch Auto-Solve animate the optimal solution. Adjust the number of disks and the animation speed at any time.

    • Goal: Move the full stack from Peg A to Peg C.
    • Rule: Only the top disk can move, and a larger disk can never sit on a smaller one.
    • Optimal moves: For n disks, the best is 2^n − 1 moves.

    Towers of Hanoi — Concept, Strategy, and Optimal Moves

    Towers of Hanoi is a classic puzzle used in maths and computer science to teach recursion, problem decomposition, and algorithmic thinking. The goal is simple: move a stack of disks from Peg A to Peg C using Peg B as a helper, without ever placing a larger disk on top of a smaller one. Despite the calm visuals, the puzzle grows exponentially more complex as you add disks, which makes it perfect for step-by-step learning.

    Optimal Number of Moves

    For n disks, the minimum (optimal) move count is: 2^n − 1. Examples:
    • 3 disks → 7 moves
    • 5 disks → 31 moves
    • 8 disks → 255 moves

    This comes from a recursive pattern: to move n disks, you must first move the top n−1 disks to the helper peg, then move the largest disk to the target peg, and finally move the n−1 disks onto it. In recurrence form: T(1)=1, T(n)=2·T(n−1)+1, which solves to T(n)=2^n−1.

    Why Teachers and Students Use It

    • Recursion: See a smaller copy of the same task inside the bigger task.
    • Proof by induction: Natural fit for showing correctness and minimality.
    • Complexity awareness: Time grows as O(2^n), highlighting exponential growth.
    • Calm practice: A gentle, rule-based environment for focus and patience.

    Beginner Strategy (Works Every Time)

    1. Always move the smallest disk in a repeating pattern (its position alternates every other move).
    2. When not moving the smallest disk, you have only one legal move—make it.
    3. Keep attention on the destination peg: you’re building the final stack from largest at the bottom to smallest on top.

    Manual Play vs Auto-Solve

    Use Manual mode to build intuition: tap a peg to pick up the top disk, then tap another peg to place it. When you want to check your understanding or demonstrate the algorithm, switch to Auto-Solve and adjust the speed. Watching the optimal sequence helps you recognise the recursive pattern.

    Common Questions

    Is there always a unique optimal solution?
    Yes, for a fixed labelling of pegs and a fixed start/target, the sequence of moves achieving 2^n − 1 is essentially determined by the rules. Variations come from which peg you treat as the helper.

    Why does it feel much harder at 7–8 disks?
    Because the shortest solution more than doubles with each extra disk. Going from 6 to 8 disks jumps from 63 to 255 optimal moves.

    What skills does this build?
    Planning, attention switching, and an intuitive sense for recursion and exponential growth—useful in programming, electronics, scheduling, and more.

    Tip: Start with 3–4 disks for quick wins. When your moves match the Optimal counter, increase disks by one and try again. Small, steady steps make the puzzle enjoyable.

    5 Fun Facts about Towers of Hanoi

    A puzzle born as marketing

    Édouard Lucas invented the Towers of Hanoi in 1883 and sold it as a wooden toy—complete with a myth about monks moving 64 disks for 264−1 moves.

    Origin myth

    64 disks would outlive Earth

    Even at one move per second, 264−1 moves take about 585 billion years—over 40× the age of the universe. That monk story was safe marketing.

    Exponential wow

    Gray codes hide inside

    The optimal solution traces a binary Gray code: each move flips exactly one bit in the disk-on-peg encoding, changing only one disk’s position at a time.

    Bit patterns

    Perfect for induction proofs

    The puzzle’s recursive structure gives a textbook example for proof by induction—one of the cleanest “see the pattern, prove the pattern” demos in CS.

    Math gem

    Robots learn with it

    Because rules are strict and states are discrete, Towers of Hanoi often appears in AI planning and robotics courses as a gentle search/heuristics sandbox.

    AI sandbox

    Explore more tools