The Rubik's cube explained

Six faces, nine stickers each, and more positions than there are grains of sand on Earth. The Rubik's cube looks like a toy, but behind it lie group theory, a famous search for the shortest solution, and algorithms that solve any position in a fraction of a second.

A scrambled Rubik's cube drawn in 3D, with white, red, green, yellow, orange and blue stickers
A scrambled Rubik's cube drawn in 3D, with white, red, green, yellow, orange and blue stickers

A puzzle from Budapest

Ernő Rubik, a Hungarian teacher of architecture and design, made the first cube in 1974 to show his students how blocks can move around each other without falling apart. It took him about a month to solve his own invention. It went on sale in Hungary in 1977 as the Magic Cube and, renamed Rubik's Cube, around the world from 1980. By the early 1980s it was a worldwide craze, and it is still one of the best-selling toys ever made.

How it is built

A 3×3×3 cube has 26 visible pieces. The six centres are fixed to a core and only spin in place, so they decide each face's colour: white opposite yellow, red opposite orange, green opposite blue in the standard scheme. Around them sit 8 corners with three stickers each and 12 edges with two. A turn of a face moves four corners and four edges; a corner always stays a corner and an edge an edge.

43 quintillion positions

The 8 corners can be arranged in 8! ways and twisted in 3⁷ ways (the last corner's twist follows from the others); the 12 edges in 12! ways and flipped in 2¹¹ ways. The corners and edges must be swapped an equal number of times modulo 2, which halves the total. That gives 8! × 3⁷ × 12! × 2¹¹ / 2 = 43,252,003,274,489,856,000 positions, about 4.3 × 10¹⁹. Turning one face a second, going through them all would take about a hundred times the age of the universe.

Why some cubes cannot be solved

Take a cube apart and put it back together at random, and the chance that it can be solved is only 1 in 12. Turning never twists a single corner (the twists of all corners always add up to a multiple of three), never flips a single edge, and never swaps just two pieces. So a cube with one twisted corner, one flipped edge or two swapped pieces is stuck in one of the other eleven "orbits". The solver checks for each of these and tells you which one it found, which usually means a sticker was coloured wrong.

The notation

David Singmaster's notation names the faces Up, Down, Right, Left, Front and Back. A letter on its own, such as R, turns that face a quarter turn clockwise as you look straight at it; R' (R prime) turns it anticlockwise and R2 a half turn. A sequence like R U R' U' is read from left to right. Counting a half turn as one move is the half-turn metric, the one solutions on this site use; counting it as two is the quarter-turn metric.

God's number is 20

How many moves does the hardest position need? In 1995 Michael Reid showed that the superflip, with every edge flipped in place, needs 20. In 2010 Tomas Rokicki, Herbert Kociemba, Morley Davidson and John Dethridge proved that 20 is always enough, by splitting the positions into 2.2 billion sets and solving each set on computers donated by Google, about 35 CPU-years of work. In the quarter-turn metric the number is 26, proved in 2014.

How the solver works

Herbert Kociemba's two-phase algorithm (1992) splits the problem in two. Phase 1 turns the cube until every corner and edge is oriented and the four middle-layer edges are in the middle layer; at most 12 moves are needed. Those cubes form a group of 19.5 billion positions that can be solved with only U, D and half turns of the other four faces, and phase 2 does that in at most 18 more. Each phase is a depth-first search that skips any branch a table says is too far from the goal. The tables are made in your browser when the page opens. The search then keeps trying longer first phases that allow shorter second ones, and stops at a solution of 20 moves or fewer or after a second and a half. Random cubes usually come out at 19 to 21 moves.

How people solve it

People use methods made of short memorised sequences instead of a search. The beginner's method solves the cube layer by layer: a white cross, the white corners, the middle-layer edges, then the yellow face. Speedcubers mostly use CFOP, named after its steps Cross, First two layers, Orientation of the last layer and Permutation of the last layer; full CFOP has 57 cases for the orientation step and 21 for the permutation step. A good beginner needs about 100 moves, a speedcuber about 55, and the solver here about 20.

Patterns

Some move sequences make pretty patterns from a solved cube. U2 D2 F2 B2 L2 R2 gives a checkerboard on every face; U D' R L' F B' U D' gives six spots, each face's centre in another colour; the superflip leaves every corner solved and every edge flipped. Pick one under Pattern, and press Solve to see how the solver undoes it.

Frequently asked questions

How many positions does a Rubik's cube have?

43,252,003,274,489,856,000, about 43 quintillion. That counts every position that can be reached by turning the faces of a 3×3×3 cube.

What is God's number?

The most moves any position needs, counting a half turn as one move: 20. It was proved in 2010 with computers donated by Google. Very few positions need the full 20; the superflip is the best-known example.

Who invented the Rubik's cube?

Ernő Rubik, a Hungarian architecture teacher, in 1974. It went on sale in Hungary in 1977 and worldwide from 1980.

What is the two-phase algorithm?

Herbert Kociemba's method of 1992 for solving the cube by computer: first reach a smaller set of positions that can be solved with only U, D and half turns, then solve within that set. It finds solutions of around 20 moves in a fraction of a second.

Why does the solver say my cube cannot be solved?

Some colourings can never come from turning: a single twisted corner, a single flipped edge, two swapped pieces, a sticker colour used too often, or two colours on one piece that do not belong together. Usually one sticker was coloured wrong. If a real cube is in that state, it was taken apart or its stickers were moved.

Ready to try it?

Open PictorX in your browser — no install, no credit card required to start.

Open the Rubik's Cube Solver