Back to blog

Algorithms & computer science

How Online Cube Solvers Work: Kociemba's Two-Phase Algorithm Explained

A 3x3 cube has 43 quintillion states, so brute-force search is impossible. Here is how Herbert Kociemba's two-phase algorithm finds ~20-move solutions right inside your browser.

By Solve My Cube Editorial Team9 min read

When you finish painting 54 stickers and click Solve in a browser, a solution of roughly 18 to 22 moves appears in a fraction of a second—without uploading your cube state to a cloud supercomputer. Considering that a 3x3 Rubik's Cube has more than 43 quintillion valid states, how can a phone or laptop browser find a near-optimal path almost instantaneously?

The answer is group theory paired with smart heuristic search: Herbert Kociemba's Two-Phase Algorithm, originally published in 1992. Understanding how it works also explains why 3x3 cube solver solutions look completely different from human layer-by-layer methods, and why our 2x2 solver and 4x4 solver use specialized engines of their own.

Why naive breadth-first search fails immediately

From any 3x3 position, there are 18 possible quarter or half turns (6 faces × 3 turn angles). Even after eliminating same-face and redundant opposite-face moves, the search tree branches by roughly 13.3× at every depth step. Searching just 10 moves deep visits hundreds of billions of states; searching 20 moves deep by brute force would outlast the age of the universe.

Human methods like CFOP avoid that explosion by solving the cube in recognizable visual milestones (Cross → F2L → OLL → PLL), trading move count (~55 moves) for simplicity. Computer solvers use a mathematical cousin of that idea called subgroup reduction.

From Thistlethwaite's 4 phases to Kociemba's 2 phases

In 1981, mathematician Morwen Thistlethwaite showed that you can progressively restrict which moves are allowed across four nested subgroups until the cube reaches the solved state—guaranteeing a solution in at most 52 moves (later tightened to 45).

Herbert Kociemba compressed that ladder into just TWO phases using one clever intermediate subgroup called G1:

PhaseAllowed MovesGoal StateApprox. State Space
Phase 1 (G0 → G1)All 18 turns: U, D, R, L, F, B (quarter & half)Orient all 8 corners, orient all 12 edges, and move the 4 middle-equator edges into the middle slice~2.2 billion coordinates (broken into small fast lookup tables)
Phase 2 (G1 → Solved)Restricted to 10 turns: U, U', U2, D, D', D2, R2, L2, F2, B2Permute corners, U/D edges, and middle-slice edges to the fully solved cube without breaking Phase 1 orientations~19.5 billion states (pruned tightly with coordinate tables)

How IDA* and pruning tables make search blazingly fast

Even within Phase 1 and Phase 2, Kociemba's algorithm does not blindly test every move. It represents the cube as compact integer coordinates (corner orientation, edge orientation, slice membership, and permutation coordinates) and precomputes small lookup tables called pruning tables.

Each pruning table stores the exact minimum number of moves needed to solve a subset of coordinates. During Iterative Deepening A* (IDA*) search, if the current depth plus the pruning table's lower bound exceeds the current move budget, the solver immediately cuts off that entire branch of millions of states. As a result, Phase 1 typically completes in 12 moves or fewer and Phase 2 finishes in under 10–12 moves—often yielding an 18-to-21-move total solution in milliseconds.

Near-optimal vs. strictly shortest (God's Algorithm)

A common question is whether Kociemba's solver always outputs the absolute shortest possible solution. The honest answer is no: once Kociemba finds a valid Phase 1 + Phase 2 solution under a practical threshold (usually around 20–22 moves), it stops rather than proving no 17-move shortcut exists across the boundary between phases. Finding a mathematically proven shortest solution (optimal solver) can take seconds to minutes on tricky scrambles, whereas Kociemba gives an immediate, practical solution that is usually within 1 to 3 moves of optimal. See our God's Number 20 guide for the math behind 20-move worst cases.

How Solve My Cube runs solvers locally in your browser

Every solver on Solve My Cube executes 100% locally on your device inside a background Web Worker thread so the 3D interface stays smooth and cancellable while solving:

  • Pre-validation before search: Before invoking the solver engine, the validator checks sticker completeness, exact color counts, unique 3x3 centers, and physical invariants (corner twist, edge flip, and parity) so impossible states return a clear diagnostic message instead of hanging.
  • 2x2 specialized corner search: Because a 2x2 has only 3.67 million states (no centers or edges), the 2x2 engine decodes the eight corners directly and searches cleanly within standard pocket-cube depth limits.
  • 4x4 staged reduction engine: A 4x4 has ~7.4 × 10^45 states—far too large for direct two-phase search—so our 4x4 solver performs staged center reduction, edge pairing, parity resolution, and final 3x3 solving in sequence.
  • Zero server uploads: Neither your sticker colors nor your cube photos leave your browser; the worker initializes and computes everything locally.

Try the local solvers and explore cube math

Editorial review and corrections

Every algorithm, cube invariant, and notation example in this guide is tested against our browser solver and 3D algorithm player. Spot an error or unclear step?

FAQ

Why does the solver give a 20-move solution that looks totally different from the beginner method?

Human methods solve one layer at a time so our eyes can track progress. Kociemba's algorithm optimizes mathematical coordinates across all six faces simultaneously, solving pieces in parallel in roughly one-fifth the moves.

Does an online cube solver need an internet connection once loaded?

On Solve My Cube, the solving computation runs entirely inside your browser's Web Worker—your cube state and photos are never sent to a remote server for solving.

Why does the first 3x3 solve sometimes take slightly longer than later solves?

Kociemba's solver builds its compact coordinate and pruning tables in browser memory once when the worker initializes. Subsequent solves reuse those tables and return almost instantly.