Mathematics · Group Theory & Permutations

The Math of the Rubik's Cube

Group Theory Permutations Algorithms 3D Thinking Pattern Recognition

Invented by Hungarian architect Ernő Rubik in 1974, the Rubik's Cube is the world's best-selling puzzle toy — and one of the richest objects in all of mathematics. It connects abstract algebra, combinatorics, and computer science in a 3-inch plastic package with 43 quintillion possible positions. Only one of them is solved.

Got a cube in front of you? Type in the colours you can see and this page will work out every move you need — then walk you through them one turn at a time. Start with your cube ↓

Bring your own cube

Type in your cube. Get the moves.

Enter the colours you can actually see. The page checks that your cube is a real one, works out a complete solution, and then walks you through it a single turn at a time while a 3D copy makes the same move.

1 Hold your cube like this

White face on the bottom. Green face pointing at you. Keep it that way for the whole solve — never spin the whole cube around, only turn the faces the moves ask for.

  • Top is yellow
  • Bottom is white
  • Front is green
  • Back is blue
  • Left is red
  • Right is orange

Standard cubes always land this way round: put white down and green in front and red really will be on your left. Centres never move relative to each other, which is why they can be printed in for you below.

2 Fill in the 54 squares

Pick a colour and click squares — or click one square and just type w y g b o r, and the cursor walks along by itself. Arrow keys move it, backspace clears.

This is your cube unfolded flat, the way a cardboard box opens out. If you lose track of which square is which, check the 3D cube — it shows exactly what you have typed so far.

Drag to spin the view. This is your cube — it updates as you type.

Turn this cube by hand instead
Up (U)
Down (D)
Right (R)
Left (L)
Front (F)
Back (B)

How This Page Knows Your Cube Is Impossible

Before it tries to solve anything, the page runs five checks on the colours you typed in. The first two are obvious. The last three are theorems.

  1. Nine of each colour. Six colours, fifty-four stickers.
  2. Every corner is a real corner, every edge a real edge. There is no white-yellow edge on a cube, because white and yellow are on opposite sides.
  3. Corner twists add up to a multiple of 3. You can never twist just one corner in place. Twist one, and another two must be twisted to compensate.
  4. Edge flips add up to an even number. Same idea: edges only ever flip in pairs.
  5. Corner swaps and edge swaps have matching parity. Swapping two corners forces two edges to swap as well.
This is where the "divide by 12" comes from. If you pulled a cube apart and reassembled it at random, only 1 in 12 of the arrangements could ever be twisted back to solved — 3 for corner twists, 2 for edge flips, 2 for parity. So if the page tells you your cube can't be solved, it is not being difficult: either a sticker got mistyped, or somebody once forced a piece back in the wrong way.

The Seven Stages of the Solution

The solution above is the beginner's method — the route almost every cuber learns first. Instead of solving the cube all at once, it breaks an impossible problem into seven possible ones, and never undoes work it has already done.

1White crossFour edges around the white centre, matching the side colours too.
2White cornersThe bottom layer finished, one corner at a time.
3Middle layerFour edges slotted in from above. Two layers done.
4Yellow crossTurn the top edges the right way up — position comes later.
5Yellow faceSune and its mirror twist the last corners upright.
6Corners homeCycle the corners into their proper places.
7Edges homeOne three-edge cycle finishes the cube.

Notice what stages 4 and 5 do: one fixes which way up pieces are, the other fixes where they are. Separating orientation from position is the single idea that makes the last layer solvable by a human. Every serious method — CFOP, Roux, ZZ — is a different way of splitting the same two questions.

Why so many moves? A beginner solve runs about 130 moves. A speedcuber using CFOP averages around 55. The shortest possible solution for any scramble is 20. The difference is memory: fewer moves means more patterns you have to recognise on sight.

Permutations & Combinations — 43 Quintillion Positions

The Rubik's Cube has exactly 43,252,003,274,489,856,000 possible configurations. That number — roughly 43 quintillion — comes directly from counting the ways the pieces can be arranged using combinatorics.

43,252,003,274,489,856,000
Distinct reachable positions of a 3×3×3 Rubik's Cube

Where does that number come from?

The cube has 8 corner pieces, 12 edge pieces, and 6 center pieces (which never move relative to each other). Mathematicians calculate the arrangements like this:

8! = 40,320 Corner arrangements
3⁷ = 2,187 Corner orientations
12! / 2 = 239,500,800 Edge arrangements
2¹¹ = 2,048 Edge orientations

Multiply the four numbers above together — the halved edge count already builds in the parity constraint (not every arrangement is physically reachable without taking the cube apart):

8! × 3⁷ × (12! ÷ 2) × 2¹¹
Total Valid Permutations
To put that in perspective: If you could examine one billion positions per second, it would take 1,371 years to check every single one. The universe is roughly 13.8 billion years old — if you started checking a new cube every second at the Big Bang, you'd have only explored a tiny fraction of them by now.

A Permutation Is an Arrangement

A permutation is any reordering of a set of objects. When you turn a face of the Rubik's Cube, you permute 8 pieces (4 corners and 4 edges around that face). A combination is a selection where order doesn't matter — but on the cube, order always matters (rotating U then R gives a different result than R then U). This is what makes the cube's math so rich.

Group Theory — The Algebra of the Cube

The set of all possible Rubik's Cube moves forms a mathematical structure called a group — specifically the Rubik's Cube Group, written as a subgroup of the symmetric group on 48 elements (the 48 visible stickers, excluding centers). This is a branch of abstract algebra that studies symmetry.

What Makes Something a Group? A group is a set with an operation (here: "apply move after move") that satisfies four axioms. The Rubik's Cube perfectly demonstrates all of them:
1 Closure

Any sequence of moves produces another valid cube state. You can never reach an "illegal" position by turning faces. The result of any two moves is also a move in the group.

2 Associativity

The order of grouping doesn't change the result: (A·B)·C = A·(B·C). Applying three moves is the same regardless of which two you group together first.

3 Identity

There exists a "do nothing" move — the solved state. Applying it changes nothing. In math notation this is often written as e or I.

4 Inverse

Every move has a reverse. U followed by U' returns to the original state. Every scramble can be exactly unscrambled.

The Order of a Move

In group theory, the order is how many times you must apply a move (or sequence of moves) to get back to the identity (the solved state).

U has order 4 (U U U U = solved) U U' = identity "Right-Hand Algorithm" (R U R' U') has order 6 Group order = 43,252,003,274,489,856,000

A single face turn like U has order 4. But sequences can have surprisingly large orders. The common "Right-Hand Algorithm" (R U R' U') has order 6 — applying it 6 times returns the cube to its original state. Some complex combinations have orders in the thousands, meaning you'd have to repeat the exact same sequence thousands of times before the cube accidentally solved itself again!

Graph Theory — The Cube as a Map

Group theory says what the moves are. Graph theory lets us see them. Make every possible cube state a vertex, and draw an edge between two states whenever one quarter turn turns one into the other. This picture is called the Cayley graph of the cube group. It has 43 quintillion vertices, and every vertex has exactly 12 edges (U, U′, D, D′, R, R′, L, L′, F, F′, B, B′).

Vertices = cube states Edges = quarter turns Solving = shortest path to the solved vertex God's number = the graph's diameter

Green = solved. Colored edges match the face turned. Hover a vertex to see its shortest route home; click it to send the walker there. Or turn faces yourself:

States at each distance (quarter-turn metric)
DistanceStatesGrowth

What the graph shows

  • Growth is exponential. Each ring holds roughly 9–10 times more states than the last (1, 12, 114, 1,068, …) until the graph starts to fold back on itself. That is why the ball must swallow all 43 quintillion states by radius 26.
  • Squares mean commuting. U then D lands on the same vertex as D then U, so those two edges close a 4-cycle. Turns of opposite faces commute; turns of adjacent faces (like R and U) never do. Zoom to radius 2 and count the squares.
  • Every cycle is a relation. Any closed loop is a move sequence that does nothing: U U U U, or (R U R′ U′) six times. The loop's length is the element's order.
  • Solving is pathfinding. A scramble is a vertex; a solution is a path to green. God's number, 20 in the half-turn metric (26 in quarter turns), is the largest distance any vertex sits from solved: the diameter.
  • Every vertex looks the same. Because a group acts the same from every state, the graph looks identical from every vertex. Graph theorists call this vertex-transitive.
Try to reason with it: Why must the graph be bipartite (can you color every state black or white so each turn switches color)? Hint: each quarter turn is an odd permutation of the 8 corners (a 4-cycle), so it flips their parity. That also means no cycle can have an odd length.

Notation & Algorithms

Speedcubers around the world share solutions using Singmaster notation, invented by mathematician David Singmaster in 1979. Six letters, three modifiers, and infinite precision.

U / U'
Up
Top face clockwise / counterclockwise
D / D'
Down
Bottom face clockwise / counterclockwise
R / R'
Right
Right face clockwise / counterclockwise
L / L'
Left
Left face clockwise / counterclockwise
F / F'
Front
Front face clockwise / counterclockwise
2 suffix
Double
U2 = turn the face 180° (two quarter turns)

Famous Algorithms

Right-Hand Algorithm — Cycles 3 corners
R U R' U'
The most common 4-move sequence in speedcubing. Repeating it 6 times returns the cube to its original state. Used in dozens of multi-step algorithms.
Sune — Orients corners on the last layer
R U R' U R U2 R'
A 7-move algorithm that rotates 3 corners of the top face. Key to many OLL (Orient Last Layer) solutions.
T Permutation — Swaps 2 corners + 2 edges
R U R' U' R' F R2 U' R' U' R U R' F'
A 14-move PLL (Permute Last Layer) algorithm. Swaps two adjacent corners and two adjacent edges simultaneously, leaving all other pieces untouched.
God's Algorithm — Maximum moves needed
≤ 20 moves (half-turn metric)
Proven in 2010 by a team using Google's computers: every possible scramble can be solved in 20 or fewer moves. This is called "God's Number." Finding the optimal solution required 35 CPU-years of computation.

How Speedcubers Use Algorithms

The CFOP method (Cross, F2L, OLL, PLL) breaks the solve into four stages, each handled by memorized algorithms. Top speedcubers know over 100 algorithms and execute them in under 5 seconds total — their fingers move faster than conscious thought, guided purely by pattern recognition trained into muscle memory.

3D Spatial Thinking

The Rubik's Cube is one of the most powerful tools ever invented for developing spatial reasoning — the ability to mentally rotate, reflect, and track objects in three dimensions. Brain imaging studies show that experienced cubers have measurably larger activation in the parietal lobe (the brain's spatial processing center) while solving.

When you solve a Rubik's Cube, you must simultaneously:

Track 20 moving pieces at once Predict positions after 5+ future moves Maintain 3D orientation while rotating the cube Recognize patterns across 6 faces simultaneously

Architects, surgeons, pilots, engineers, and mathematicians all rely on strong spatial reasoning. Research from universities including Carnegie Mellon and MIT has found that Rubik's Cube practice measurably improves spatial IQ scores — making it one of the few toys with documented cognitive benefits.

The cube also introduces coordinate systems: every piece can be described by (x, y, z) coordinates, and every move is a rotation of a slice around one axis. This is the same mathematics used in 3D animation, robotics, flight simulation, and spacecraft attitude control.

Pattern Recognition & God's Number

A scrambled Rubik's Cube looks like chaos. A skilled cuber looks at the same cube and sees patterns — recognizable configurations with known solutions. This is a profound illustration of how mathematical expertise transforms perception: what looks random to a novice is structured information to an expert.

God's Number = 20

In 2010, mathematicians Tomas Rokicki, Herbert Kociemba, Morley Davidson, and John Dethridge proved the following: no matter how scrambled a Rubik's Cube is, it can always be solved in 20 or fewer moves. This maximum is called God's Number — the number of moves an omniscient being would need in the worst case.

The proof required checking all 43 quintillion positions. They used a symmetry reduction to collapse it to about 2.2 billion equivalence classes, then verified each using computers donated by Google. The total computation took 35 CPU-years, completed in weeks on modern hardware.

Pattern Databases in AI Solvers

The algorithm that enabled God's Number proof — Kociemba's two-phase algorithm — works by recognizing patterns. Phase 1 finds a short sequence that moves the cube into a special subgroup where only certain moves are needed. Phase 2 solves from there. This two-stage pattern recognition makes it fast enough to run on a phone.

Modern AI solvers (like DeepCubeA from USC, 2019) use deep reinforcement learning — the AI taught itself to solve the cube without human knowledge of algorithms, purely by exploring positions and learning which patterns lead toward solved. It solves in an average of 28 moves and finds solutions humans hadn't written algorithms for.

Practice Problems

0 / 6 correct
Hint: Each turn is 90°. A full rotation is 360°. 360 ÷ 90 = ?
Hint: This is the "order" of the move. The lesson states it directly.
Hint: 8! = 8×7×6×5×4×3×2×1 = ?
Hint: It was proven in 2010. The lesson states it.
Hint: 3 ways the corner twists can land, times 2 for edge flips, times 2 for parity. Multiply them.
Hint: 43,252,003,274,489,856,000 ≈ 4.3 × 10¹⁹. Count the digits after 4.3.