A Rubik's cube has 54 colored stickers and six faces that turn. Every twist shuffles the stickers in a fixed, reversible way, and that turns the toy into a piece of mathematics: moves are permutations, they combine like numbers do, and finding the shortest way back to solved is a search through an enormous maze. Here you'll turn a cube, count its positions exactly, take moves apart into cycles, and search every position of the small 2×2×2 cube to find its hardest scrambles.
The cube is built from 26 small pieces. The 6 centers (one sticker each) never move relative to each other, so they fix each face's color. The 8 corners have 3 stickers and the 12 edges have 2. A move turns one face. Cubers name them with the face letters U (up), D (down), L (left), R (right), F (front), B (back), a system from David Singmaster: a plain letter is a quarter turn clockwise as you look straight at that face, a prime (R′) is counterclockwise, and a 2 (R2) is a half turn. A position is any arrangement you can reach by turning.
How to read this: you see three faces at a time: U on top, F in front, R on the right. Drag the cube to see the others; dragging only changes your view, never the position. Each turn animates the layer of 9 pieces that moves. The counters on the right count your moves since the last scramble or reset.
Try this: press R four times and the cube comes back. Then apply R U R′ U′ six times in a row and watch it come back too.
Take the cube apart and put it back together any way at all. The corners can go into the 8 corner spots in 8! = 8·7·6·…·1 orders, and each can sit in 3 twists. The edges can go into 12 spots in 12! orders, each in 2 flips. But turning faces can't reach all of that. Three rules hold for every position you can reach by turning:
Twist each corner 0, 1 or 2 steps clockwise from its correct orientation: the total is always a multiple of 3, so the last corner's twist is forced (37, not 38). The number of flipped edges is always even (211, not 212). And a quarter turn moves 4 corners around a loop and 4 edges around another loop, each an odd permutation (one made of an odd number of swaps), so corners and edges always have the same parity; that halves the count. Reassembling at random gives a position you can turn back to solved only 1 time in 12.
A permutation is a rule that says where each item goes, like a seating chart. Any sequence of moves, however long, is one permutation of the 48 stickers that can move. Follow one sticker: it jumps to a new spot, then another, and eventually comes back where it started. That loop is a cycle. Every permutation splits into separate cycles. Repeat the sequence and each sticker steps once around its own cycle, so the cube is solved again exactly when every cycle is complete at the same time. That count of repeats is the sequence's order.
How to read this: on the left is the cube after the repetitions so far. On the right is the cube unfolded flat, with every sticker spot tinted by the length of the cycle it belongs to, and the number in it is that length. Gold arrows trace the selected cycle: the sticker in each spot jumps to the spot the arrow points at. Dark spots are stickers the sequence leaves alone. Click a spot, or a cycle in the list, to trace it.
Try this: pick R U2 D′ B D′ and press Repeat it. It takes 1,260 repetitions to come home.
How to read this: this tracks each individual sticker, so a sticker only counts as home in its own spot, even when a same-colored sticker would look right. After k repetitions, a sticker is home when its cycle length divides k. The curve shows how many of the 48 stickers are home after each k. It touches the top only at multiples of the order.
The least common multiple is the smallest number every cycle length divides. The page computes it as lcm(a, b) = a·b / gcd(a, b), with the greatest common divisor from Euclid's algorithm on 003 · Number theory. R U has cycles of 15, 7, 7 and 3 stickers. The 15 is five corners that chase each other round and come back twisted, so they need 3 laps of 5. lcm(15, 7, 3) = 3·5·7 = 105.
All positions of the cube, with "do one, then the other" as the way to combine them, form a group: combining two positions gives a position, every move can be undone, and doing nothing is the identity. No position of the cube has order above 1,260, and R U2 D′ B D′ is one that reaches it. The 1,260 bound comes from checking which cycle shapes the corner and edge rules allow; the page verifies this sequence's order, not the bound.
How many moves does the hardest position need? The answer is called God's number: the fewest moves that always suffice, even if you knew the perfect solution every time. For the full cube the search is far too big for a browser, so here is the 2×2×2 cube, which is just the 8 corners. Hold its back-down-left corner still and only U, R and F ever need to turn; turning L is the same as turning R and then rotating the whole cube. That leaves 7! · 36 = 3,674,160 positions. The page visits every one with a breadth-first search: start at solved, find everything 1 move away, then everything 2 moves away that hasn't been seen, and so on, like ripples spreading out. It is the shortest-path search of 002 · Graphs on a graph where every position is a node and every move is an edge of length one. The ripple number where a position is first reached is its distance: the length of its shortest solution.
How to read this: the 2×2×2 cube, turned with U, R and F only. The back-down-left corner, hidden from this view, never moves. After each change the page looks the position up in the search results and shows its distance. Solve plays a shortest solution: each move lowers the distance by exactly one.
Try this: scramble a few times. Most scrambles land 8 to 10 half-turn moves from solved; finding an 11 is rare.
How to read this: each bar is how many positions sit at that distance from solved. In the half-turn count R2 is one move; in the quarter-turn count it is two. The search itself usually takes under a second; the chart then reveals its results one distance at a time. Log scale makes the tiny first and last bars visible.
Try this: switch to Log and compare the far right ends: 2,644 positions need 11 half turns, and 276 need 14 quarter turns.
Green counts equal the published table for the 2×2×2 with one corner fixed.
Breadth-first search needs a record for every position, and the 3×3×3 has 43 quintillion. Counting gives a first answer for free. Skip sequences that waste moves (the same face twice in a row, or D then U when U then D does the same thing). There are still too few sequences of 17 or fewer moves to reach every position, so some position needs at least 18.
The true answer is 20 in the half-turn count, proved in 2010 by Tomas Rokicki, Herbert Kociemba, Morley Davidson and John Dethridge. They split the positions into 2.2 billion sets of about 20 billion each, used symmetry to skip most, and solved the rest with about 35 CPU-years donated by Google. One position, the "superflip" with every edge flipped in place, had already been shown in 1995 to need 20, so 20 is exact. In the quarter-turn count God's number is 26, settled in 2014.
The near layers can be counted here directly by the same ripple search on whole sticker states.
Searching a huge space by trying moves and backing up is the idea behind 000 · N-Queens. Labeling every position of a game by working through all of them is also how 025 · Nim sorts winning positions from losing ones.