The Mathematics of the Rubik's Cube: Permutations, Groups, and the State Graph

I saw an animation that represents a Rubik's Cube as three groups of rings, and I wanted to understand two things: why can those dots stand in for the colored stickers on the cube? And does understanding this representation mean understanding how to solve the cube? These notes start from the basics of group theory and the Rubik's Cube, then work step by step toward permutations, commutators, and shortest paths. [1]

Animation screenshot showing a Rubik's Cube and three groups of rings side by side

1. Group Theory Basics

Sets, Mappings, and Permutations

A set is a collection of objects. For example, P={1,2,3,4} is a set consisting of four labels. A mapping f:P→P assigns a unique output to each input. Writing f(1)=3 means that label 1 is sent to label 3.

If different inputs are never sent to the same output, and every output has an input corresponding to it, the mapping is a bijection. For finite sets, a bijection rearranges all the objects, with neither repetition nor omission. A bijection from a set to itself is called a permutation. Rearranging four labeled cards is an example.

Why emphasize bijections? Because every output can be uniquely traced back to its original input. The operation can therefore be undone. Merging, discarding, or duplicating cards all lose this reversibility.

Composition of Operations

"Operation" does not only refer to addition or multiplication of numbers. First performing one action a and then another action b can also be combined into a new action, denoted a∗b . For example, first rotating a square clockwise by 90∘ and then by 180∘ has the same overall effect as rotating clockwise by 270∘ .

In what follows, the multiplication sign is omitted, and ab means "first do a , then do b ." This is the uniform convention for action sequences used throughout this article. It differs from the notation for ordinary function composition in many textbooks: f∘g usually means first do g , then do f . When reading formulas, one must recognize which convention is being used.

The same overall effect is regarded as the same operation. A full rotation and no rotation at all make no difference to the final positions of the square's four vertices; group theory compares final effects here and does not record the path traced by the hand.

Definition and Axioms of a Group

Let G be a set of operations, and ∗ the operation that combines them. If the following conditions are satisfied, (G,∗) forms a group. These conditions hold for arbitrary elements of the set. [2]

Closure: After performing two operations from the set, the resulting overall operation still belongs to the set.

a,b∈G⟹a∗b∈G.

Associativity: When performing three things in succession, one may treat the first two as a whole, or the last two as a whole.

(a∗b)∗c=a∗(b∗c).

Here the order of the actions is not swapped; only the grouping is changed.

Identity element: There exists an operation e that "changes nothing," and placing it before or after any operation does not affect that operation.

e∗a=a∗e=a.

Inverse element: Every operation a has an operation a−1 that undoes it.

a∗a−1=a−1∗a=e.

Some textbooks include closure in the definition of a "binary operation" and therefore list only three additional axioms; the content is the same. The definition of a group does not require commutativity a∗b=b∗a . Associativity concerns parentheses, while commutativity concerns order; they are different questions.

Square Rotations and Cyclic Groups

Label the four vertices of a square A, B, C, D. Allowing only rotations about the center by integer multiples of 90∘ , and letting r denote one clockwise rotation, we obtain

C4={e,r,r2,r3},r4=e.

The exponent indicates the number of repetitions, r2=rr ; r0=e . When two rotations are combined, the exponents are added, and any part exceeding a full turn can be discarded.

rarb=r(a+b)mod4.

"Modulo 4" means dividing by 4 and keeping the remainder, for example 5mod4=1 , so r3r2=r . Since rr3=r4=e , the inverse of r is r3 ; r2 is its own inverse. This example satisfies commutativity, but one cannot infer from this that other groups do.

Try rotating forward four times, or rotating forward once and then backward once. Compare the vertex labels, not just the outer outline of the square.

Square Rotations and the Cyclic Group C₄

Cycle Decomposition of Permutations

The cycle (1 2 3 4) denotes a simultaneous operation: 1→2 , 2→3 , 3→4 , 4→1 . It is not a four-step instruction in which four objects take turns acting. Walking backward along the cycle gives the inverse permutation (1 4 3 2) .

A permutation may contain multiple mutually disjoint cycles. For example, (1 2)(3 4 5) simultaneously swaps 1 and 2, and cycles 3, 4, 5. Since the objects acted upon do not overlap, these two cycles can be executed in either order; cycles that do overlap generally cannot.

Any finite permutation can be decomposed in this way. The method is to start from one label, repeatedly trace where it is sent, until returning to the starting point; then start again from a label not yet visited. Labels that do not move are cycles of length 1 and are usually omitted.

Basic Concepts of Groups and Parity of Permutations

The order of a group |G| is the number of elements in the group. The order of an element ord(a) is the smallest positive integer k such that ak=e holds. In C4 , the order of the group is 4, but the order of the element r2 is 2. For mutually disjoint cycles, in order for them all to return to their original positions simultaneously, the number of repetitions must be a common multiple of all the cycle lengths; therefore the order of a permutation equals the least common multiple of these lengths.

A set of elements that can generate all operations through repeated composition and inversion is called a set of generators. The notation ⟨r⟩=C4 means that r generates the entire rotation group. If a subset of elements chosen from a group still forms a group under the original operation, it is called a subgroup. For example, {e,r2} is a subgroup of C4 .

All permutations of n distinct objects form the symmetric group Sn . The first position has n choices, the second has n−1 , and multiplying successively gives its order

|Sn|=n!=n(n−1)⋯2⋅1.

Finally, we introduce a tool for determining whether an arrangement is valid. Swapping only two objects is called a transposition. Any permutation can be decomposed into transpositions; although the decomposition is not unique, the parity of the number of transpositions remains consistent, so one can distinguish even permutations from odd permutations. Using the sign sgn(π) , even permutations are +1 and odd permutations are −1 ; when composed, their signs multiply. [3]

A cycle of length k can be decomposed into k−1 transpositions, so

sgn(k-cycle)=(−1)k−1.

For example, a 4-cycle is an odd permutation, and a 3-cycle is an even permutation; two odd permutations composed together form an even permutation. An important restriction on the Rubik's cube discussed later comes from this rule.

2. Structure and Representation of the 3x3 Cube

Cubies, Stickers, and State

The appearance of a 3x3 cube is 3×3 stickers per face, six faces in total. But when learning its rules, you should first identify the cubies that actually move together.

Cubie Count Stickers per cubie Information to track
Center 6 1 Provides the reference color for each of the six faces
Edge 12 2 Position and flip orientation
Corner 8 3 Position and twist orientation

Therefore the total number of stickers is 6+12×2+8×3=54 . For example, the three stickers on the white-red-green corner belong to the same piece of plastic, and any turn must carry them together. They cannot be arranged freely like three independent cards. [4]

A sticker is an object that can be tracked, and a sticker position is a fixed cell on a given face. The white sticker can move from the top face to the front face, but the definition of "the upper-left cell of the top face" remains unchanged. The entire state, however, must record the positions and orientations of all cubies; it cannot describe only a single sticker.

Positions and Orientations of Cubies

When an edge occupies a position, it has two possible orientations. For example, even if the white-red edge returns to the position between the white and red centers, it may have the white side facing the red face and the red side facing the white face; this is called a flip.

A corner in a corner position has three possible orientations. The white-red-green corner can be twisted 120∘ about its own corner axis while still occupying the original position, yet causing its three stickers to face the wrong faces.

Therefore, solving requires satisfying two things simultaneously: the cubie's position is correct, and the cubie's orientation is also correct. This article discusses the common solid-color 3x3 cube and does not consider whether arrows, text, or patterns on center stickers are aligned.

Reference Frame and Turn Notation

Fix a set of viewing directions: top white, bottom yellow, front green, back blue, right red, left orange. The opposite face pairs are white/yellow, green/blue, and red/orange. The center cubies define this coordinate system and remain fixed in the model used in this article.

Face Up Down Right Left Front Back
Notation U D R L F B

A single letter denotes a clockwise turn of that face by 90∘ , an apostrophe denotes counterclockwise 90∘ , and the suffix 2 denotes a turn of 180∘ . For example, R' is a counterclockwise turn of the right face, and U2 is a half turn of the top face. Clockwise must be judged from outside the face being turned, looking directly at that face; the back and bottom faces follow the same rule. [5]

Turning an outer layer moves four corner cubies and four edge cubies simultaneously, along with the orientation of that face's center; the position of a solid-color center itself does not change. This article only allows turns of these six outer layers. Picking up the cube and changing its orientation counts as changing the viewing coordinates and is not treated as a new scrambled state for now.

3. The Rubik's Cube Group and Composition of Operations

Taking the six basic face turns, their inverses, and the operations obtained from any finite combination of them, we define

G=⟨U,D,R,L,F,B⟩.

Closure is already included in the definition: concatenating two legal move sequences still yields a legal move sequence. Associativity comes from the composition of operations—the grouping of three move sequences does not affect the actual order of execution. The empty move is the identity element e . Every step can be reversed, and the entire sequence also has an inverse, so these operations form a group. [2]

Move Sequences and Group Elements

Turning the right face four times in a row returns every sticker to its original position, so

R4=e,R−1=R3.

R R R R and the empty move differ in notation and length, but they represent the same group element. An element of the Rubik's Cube group can be understood as "a definite final permutation," while a move sequence is one way of describing it. Finding a short solution means searching for a shorter expression among many equivalent move sequences.

Number the 48 non-center stickers, and any legal operation corresponds to a permutation; moreover, different operations can be distinguished by the final positions of these numbered stickers. Therefore G can be viewed as a subgroup of S48 . It occupies only a very small part of all sticker permutations, because the binding of cubies and the mechanical structure restrict the allowed changes.

Inverses of Composite Operations

If we first do A and then B , to undo them we should first undo the last move B and then undo A . Thus

(AB)−1=B−1A−1.

For example, the inverse of R U F2 is F2 U' R'. When the two sequences are concatenated, the middle F2 F2 cancels first, followed in turn by U U' and R R'.

If we record the entire scrambling process, we can restore the cube this way. But faced with a state of unknown origin, we usually do not know the original move sequence. Invertibility guarantees that an undoing operation exists, but it does not directly tell us how to find it.

Commutativity of Operations

The right layer and the left layer do not overlap, so RL=LR . The adjacent right layer and top layer share cubies, so turning the right face first changes the objects involved in the subsequent top turn; therefore RU≠UR .

Whether two operations are equal can be checked rigorously: finding a single sticker that ends up in a different position under the two orders is enough to prove that the two permutations are different. What is being compared here is the entire permutation, not some local picture that happens to have matching colors.

4. Permutation Representation of Face Turns and the Ring Model

Sticker Numbering and Cycle Decomposition of Face Turns

Looking squarely at the outer side of each face, number the nine positions row by row from 1 to 9, with the center as 5. U1 denotes the upper-left position of the top face; the sticker occupying that cell at the solved starting state is also named the "original U1 sticker." After a turn, the two may no longer coincide.

Use the continuous orientation of the six-face unfolded diagram: the front face connects upward to U, downward to D, rightward to R, leftward to L, and B attaches to the right of R. This keeps the numbering below consistent with the animation. [6]

A single U turn produces five mutually disjoint 4-cycles:

U=(U1 U3 U9 U7)(U2 U6 U8 U4)(R1 F1 L1 B1)(R2 F2 L2 B2)(R3 F3 L3 B3).

The first two cycles are internal to the top face: four corner stickers cycle, and four edge stickers cycle. The last three cycles connect the top rows of the four side faces, moving 12 stickers in total. Thus one outer-layer quarter turn changes the positions of 8+12=20 numbered stickers in total, while the remaining 34 stay fixed.

Note that a "corner sticker" here is one visible face on a corner cubie. The three stickers of a corner cubie appear in different sticker cycles; this does not contradict the fact that they still belong to the same cubie.

Construction of the Nine-Ring Model

Take right, up, and front as the positive directions of the x,y,z axes. Each direction has three layers, with coordinates written as −1,0,1 . Fix one layer and observe only the stickers flowing among the four side faces around that axis: each face contributes three stickers, for 12 in total. Drawing this side band as a closed curve yields one ring.

Three axes times three layers each gives nine rings in total. Drawing the three rings of the same axis as concentric circles produces the three-group ring structure seen in the screenshot.

A sticker on the front face has its normal along the z axis. It lies both on some side band with fixed x and on some side band with fixed y , so it belongs to two rings in the diagram. Each ring has 12 positions, and each position is counted twice, hence

9×122=54.

Another way to count is by intersections: among the three ring groups there are three group pairings, each pairing contains 3×3 pairs of circles, and each pair intersects twice, so the total is also 3×9×2=54 . The chosen radii and arrangement avoid multiple intersections coinciding.

Modular Arithmetic Representation of Side-Band Turns

Along a given ring, temporarily label the 12 positions as 0,1,…,11 . A quarter turn moves the three-cell strip of one face to the next face, corresponding to

j↦j+3(mod12).

Thus this step splits into three 4-cycles:

(0 3 6 9)(1 4 7 10)(2 5 8 11).

A reverse turn changes adding 3 to subtracting 3. After four repetitions every point returns to its original position, consistent with the actual cube. If all points were instead advanced by one step along the ring, the result would be a 12-cycle, which does not correspond to any legal face turn here.

Synchronized Permutation of Stickers Within a Face

The rings above only depict the side bands. When turning U, the eight non-center stickers on the top face itself must also be permuted. They occur within the nine-point cluster corresponding to the U face, and cannot be ignored by focusing only on the sliding of the large rings.

In the animation below, select U and step through slowly: 12 points move on the large rings, while another 8 points move within the face cluster. Tracking the numbers shows that even when same-colored faces appear unchanged, stickers may still have been permuted.

One Turn: the 3D Cube and Sticker Rings

Correspondence and Limitations of the Ring Model

The ring arrangement assigns new planar coordinates to the 54 positions while preserving the start-point/end-point correspondence of every legal move. As long as each position can be uniquely recovered, the rearrangement does not lose the complete sticker state.

But the fact that curves intersect does not mean stickers can freely switch tracks. A legal move updates an entire layer simultaneously; one cannot pick a single dot and move it alone. The line segments in the diagram primarily express a drawing relationship, not a path along which a single bead may travel independently.

The radii of the circles, the on-screen distances, and the animation speed are also not part of the group structure. Within a face cluster, curves are drawn to connect the correct endpoints in a way that is easy to observe; different continuous trajectories can represent the same discrete permutation. To judge whether the model is correct, one must check the full sticker correspondence after every step.

5. Commutators, Conjugation, and Local Operations

Definition and Role of the Commutator

Define the commutator

[A,B]=ABA−1B−1.

Execution still proceeds from left to right. It differs from the sequence ABB−1A−1 that fully undoes AB by one ordering. If A,B commute, the order can be adjusted and everything cancels, yielding [A,B]=e ; conversely, if the commutator equals e , the two can also be shown to commute.

Therefore [R,L] ultimately changes no stickers, while [R,U] leaves a change behind. When designing Rubik's cube algorithms, people choose operations whose effects mostly cancel each other out, so that the remaining change is concentrated on a small number of pieces. The commutator provides a method for constructing local effects, but not every commutator "moves only three pieces." [7]

Cycle Decomposition and the Order of a Commutator

Let C=RUR−1U−1 . Computed using the sticker numbering above, it contains two 6-cycles, two 3-cycles, and all other stickers are fixed. Therefore

ord(C)=lcm(6,6,3,3)=6,C6=e.

Here the least common multiple ensures that the four cycles return to their original positions simultaneously. Looking only at piece positions, one might notice that some corner pieces return to their original corner after two repetitions, yet still have the wrong orientation. The full sticker permutation records both position and orientation, so it gives the correct period.

Verifying with numbered stickers has another advantage: two stickers of the same color look very similar in a rendering, but the numbering will not mistake a real change of position for "no change."

Conjugation and Transforming the Location of Action

Suppose A is a local operation one has already mastered, and P is a setup move. Then

PAP−1

means first using P to bring the target object into the region affected by A , executing A , and finally undoing the setup move. Objects not affected by A return to their original state, while the affected object retains the local change. This is called conjugation.

Conjugation preserves the cycle lengths and order of a permutation. It can be understood as follows: a cycle that originally ran through one set of indices is uniformly moved to another set of indices, with the internal structure of the cycle unchanged. The setup move must still be a legal operation, and one must pay attention to piece orientation; one cannot arbitrarily designate a few independent stickers to "transport."

Below, first compare RU with UR, then select a commutator. Finally observe F[R,U]F': its location of action has changed, but the cycle type remains consistent with [R,U].

Move Order, Commutators, and Conjugation

This also explains a common structure in Rubik's cube algorithms: first bring the pieces to be processed to a familiar position, execute the local algorithm, then undo the setup move. Once the structure is understood, algorithms can be inspected and combined, rather than being treated as a string of unrelated turns.

6. State Invariants and Reachability

State Coordinates and Invariants

An invariant is a quantity that remains unchanged no matter how many legal moves are applied. When looking for invariants, you can first examine the basic generating moves: if all of them preserve some quantity, then any finite composition of them preserves it as well.

After fixing the six centers, record the state as corner permutation πc , corner orientation ti , edge permutation πe , and edge orientation fi . Corner orientation has three values, denoted by 0,1,2 ; edge orientation has two values, denoted by 0,1 . The orientation labels here must follow a consistent convention across all positions; they cannot be judged arbitrarily from the observer's left or right. [4]

The three slots of a corner position are numbered with the same chirality, with the U/D slot as 0. For example, the up-right-front corner is numbered 0, 1, 2 in the order U, R, F; the down-right-front corner is numbered in the order D, F, R. Whichever slot the white/yellow sticker falls into is the orientation value. For edge positions, the first slot takes U/D when available; when there is no U/D, it takes F/B. The reference color of an edge is also chosen by this priority: if it falls in the first slot, the value is 0; in the other slot, it is 1. The constraints below use this convention.

Corner Orientation Constraint

All legal states satisfy

∑i=18ti≡0(mod3).

Turns of the top and bottom faces merely permute the orientation values, while a quarter turn of any other face adds two 1s and two 2s to the four affected corners, for a total increment of 6≡0(mod3) . The orientation sum is therefore preserved.

Twisting a single corner by 120∘ makes the sum become 1 or 2, which cannot return to the solved value of 0 through legal face turns. Twisting two corners in opposite directions does not violate this constraint.

Edge Orientation Constraint

Edges satisfy

∑i=112fi≡0(mod2).

Under a consistent, commonly used orientation convention, a single generating move changes the orientation values of either zero or four edges, so the total change is even. Therefore a state with exactly one flipped edge and all other pieces unchanged is unreachable. Note that this refers to the orientation coordinate; it cannot be naively equated with "whether the white sticker faces up."

Permutation Parity of Corners and Edges

An outer-layer quarter turn simultaneously produces a 4-cycle of corners and a 4-cycle of edges at the level of piece positions. Each is an odd permutation, so every turn flips the parity of both. Starting from the solved state, they always remain equal:

sgn(πc)=sgn(πe).

Swapping two edges alone or two corners alone violates the condition. Note that this concerns the permutation of pieces: the same turn contains five 4-cycles at the sticker level, and the parities of these two kinds of objects must not be conflated. [2]

Corners have 8! permutations; the first seven orientations can be chosen freely and the eighth is determined by the mod-3 sum, giving 37 orientation combinations. Edges likewise have 12! permutations and 211 orientation combinations. The two permutations must have the same parity, so divide the product by 2:

|G|=8!12!372112=43252003274489856000.

This equation also relies on a fact: for the correct set of pieces, the three conditions above are not only necessary but also sufficient. Sufficiency requires constructions that correct orientations in pairs and handle even permutations with 3-cycles; if the two permutations are both odd, first perform a quarter turn to make them both even. With appropriate conjugation, local constructions can be applied to different positions. Merely writing out the product of counts does not substitute for this reachability argument. [3]

Here the center reference frame has already been fixed, so we no longer divide by the 24 choices of overall orientation. Nor can "nine stickers of each color" be treated as a sufficient condition: an arbitrary sticker layout may still contain color pairs or corner combinations that do not exist at all.

Sticker Graphs and State Graphs

A graph consists of vertices and the edges connecting them. Following edges from vertex to vertex yields a path; if every edge has cost 1, the shortest path is the one with the fewest edges.

Different graphs can be built for the Rubik's Cube. The points in the circular diagram are sticker positions, and one picture jointly describes the whole cube. In the state graph used for solving, a point is a complete legal cube state, and an edge represents performing one allowed move. A single node of the latter contains all the information of an entire picture of the former.

Taking group elements g∈G as vertices and, for each allowed move s , connecting g with gs , we obtain the group's Cayley graph. With the solved state corresponding to the identity e , solving is the search for a path

gs1s2⋯sk=e

The solution sequence represents g−1 , and a shortest solution is the shortest expression under the specified move metric. The shortest routes of individual stickers cannot simply be combined, because whole-layer moves are bound to the cubies and require all objects to move in coordination.

The Cayley Graph of a Sixteen-State Subgroup

For the moment, allow only U and D turns. They commute, and each returns to its original position after four turns, so every reachable state can be written as

UaDb,a,b∈{0,1,2,3}.

The two exponents record the changes of the upper and lower layers respectively; different exponent pairs produce different states. This subgroup has 4×4=16 elements, denoted

H=⟨U,D⟩≅C4×C4.

Here the symbol × combines two independent rotations into an ordered pair, with the operation adding the two coordinates separately modulo 4; ≅ indicates that the two descriptions have the same operational structure.

In the figure below, node (a,b) represents the entire UaDb cube. Selecting a node lets you view its actual state directly. It is a restricted subproblem of the full cube problem and does not mean that any arbitrary scramble can be solved using only U and D.

BFS and Shortest Solutions Among 16 Cube States

Breadth-First Search and Shortest Paths

Breadth-first search (BFS) uses a first-in-first-out queue. It first visits the starting point, then the states reachable in one move, then the new states reachable in two moves, expanding outward layer by layer. Each time a new node is discovered, it records which parent node it came from and through which move it was reached.

Because every edge has cost 1, when the target is first discovered, all possibly shorter layers have already been processed. Tracing back from the target to the start along parent pointers, then reversing the recorded order, yields a shortest solution.

A visited set is used to avoid duplication. U D and D U are different move sequences, yet they lead to the same node; four U turns return to the start. If every move sequence were treated as a new state, the search would repeat work. The animation actually computes neighbors and parent pointers, then displays the results layer by layer.

Move Metrics and the Diameter of the State Graph

QTM is the quarter-turn metric, where one 90∘ counts as one move and a half turn counts as two. HTM is the half-turn metric, where one 90∘ or 180∘ each counts as one move. The starting point (2,2) requires four moves in QTM, while in HTM it can be solved in two moves using U2 D2.

For the full 3×3×3 cube, the proven maximum shortest distances are 26 for QTM and 20 for HTM. This is called the diameter of the state graph; since all nodes in a Cayley graph have the same local structure, the distance between the two farthest points also equals the maximum distance from the solved node. [8][9]

"Every state can be solved within 20 moves" does not mean every state requires 20 moves, nor does it guarantee that an arbitrary algorithm will produce such a solution. Recording a scramble and playing it backward only exhibits one solution; it does not rule out shorter paths.

The full graph has roughly 4.3×1019 nodes and cannot be expanded directly the way this small experiment can. Practical solvers use heuristic lower bounds, precomputation, and subgroups to reduce the search. The two-phase algorithm first sends the state into a subgroup with constrained orientations, then solves it within that subgroup; such structured search quickly yields short solutions, but "using two phases" does not by itself guarantee global optimality. [10]

A Unified Perspective on Permutations, Groups, and Graphs

The ring diagram makes it easier to track permutations of the same set of stickers. Group theory explains how these operations compose, invert, and which states are reachable; the state graph further writes a solve as a path. When understanding this, always keep two things in mind: whether the dots represent stickers or complete states, and which objects must move simultaneously in a single legal operation.

References

  1. Inspiration screenshot: the ring animation posted by The Math Flow. The original creator has not been verified; what is kept here is the screenshot as seen while reading.
  2. Michael Hutchings — The mathematics of Rubik's Cube. Groups, permutations, cube operations and invariants; slides pages 8–9, 23, 28–34.
  3. Jaap Scherphuis — Group Theory for puzzles. Permutation parity, 3-cycles, conjugation and commutators; sections 5, 7.
  4. Herbert Kociemba — The Cubie Level. Position and orientation representation of corners and edges.
  5. WCA Regulations — Article 12: Notation. Notation for face turns, inverse turns and half turns.
  6. Herbert Kociemba — The Faceletlevel. Sticker-level numbering and position representation.
  7. Jaap Scherphuis — Useful Mathematics. The Conjugation and Commutation sections.
  8. God's Number is 20. The 2010 computational proof of the full 3×3×3 cube diameter in HTM.
  9. God's Number is 26 in the Quarter Turn Metric. The 2014 computational proof of the diameter in QTM.
  10. Herbert Kociemba — The Two-Phase Algorithm Coordinates. Two-phase solving and subgroup coordinates.