The Maths Behind the Rubik’s Cube

My parents gave me a Rubik’s Cube for my tenth birthday along with a very friendly-looking guide on solving it. Not too soon afterwards, I decided to learn how to solve it. It turned out that my motivation was far below the requirements.

As with any tutorial on how to solve the cube, the book listed several sets of moves that I had to learn and apply in different ways depending on what configuration the cube was in. Granted, the book was sufficiently easy to understand, but nothing could have prepared me for the sheer volume of algorithms that were thrown at me.

This little book must have given me at least fifty algorithms, averaging around 15 moves in length. My ten-year old self simply wasn’t ready for a commitment of this magnitude; I was out of my depth in a similar sort of way that a snake is on a bicycle, or a Magcargo is against a Swampert.

I managed to solve it a couple of times, but not without at least an hour of constantly consulting the book, struggling to hold the book open while using my hands to perform the moves and getting frustrated when I was unable to multitask effectively. Eventually I deemed it best to leave this chapter of my life behind me.

Six years later one of my friends brought his own cube into school, and I was baffled at how easily he had managed to memorise all of the algorithms. Unexpectedly, he wondered how I had been unable to memorise them; he appeared to have had little to no trouble.

I showed him the book the next day, and he couldn’t comprehend why someone would make solving the cube so long-winded. I searched for a foreword or author’s note for an explanation of some sort, and it was then that I discovered the book had been published in 1981 – only months after the cube was internationally released. Since then, I realised, methods of solving the cube have been heavily refined and made simpler, faster and generally more efficient. That same day, I found this guide to the Beginner’s Method and began to learn. To my surprise, it was astoundingly simple and I was able to solve the cube completely from memory within an hour. If you can’t solve the cube as of yet, I strongly urge you to learn how – it’s relatively easy, yet people are still amazed at one’s ability to solve a cube.

That anecdote stretched out far longer than I ever intended it to. However, it is still relevant somewhat.

A few other friends all became interested in cubing after this, and while they were moving on to faster, more complex methods of solving the cube, I found myself much more interested in the mathematics of the cube.

Firstly, as the cube has 26 pieces (or cubies, as they’re informally known) and 9 slices (as pictured below) that can all be moved independently of one another, it has a vast number of possible configurations. I began by asking the inevitable: how many possibilities are there?

Slices demo

This is actually a rather easy question to answer in principle, but it requires a little explanation. We just have to consider all the possible positions of each cubie (where it is on the cube), and all the possible rotations of each cubie (which way its colours are facing, regardless of its position).

Let’s start with the positions of the corner cubies. There are 8 corner cubies, so we can say that there are 8! (8 x 7 x 6 x 5 x 4 x 3 x 2 x 1) ways to arrange the corner cubies.

Next, let’s look at the rotations of the corner cubies. There are 3 possible ways to rotate each corner cubie, as I’ve shown below. However, 7 cubies can be rotated freely, while 1 depends on the rotations of the rest. We can say that there are 37 possible corner rotations.

Complete Corner rotation demo 1 Corner rotation demo 2

We’ll move on to the edge cubies. There are 12 edge cubies, so we’d assume that there are 12! ways to arrange the edge cubies. However, we have an even permutation for the corner cubies (meaning an even number of position swaps), which means that there must be an even permutation for the edge cubies too. This sounds complicated, but it’s just a limitation of the laws of the cube. We have to divide this number by 2, leaving us with 12!/2 possible ways to arrange the edge cubies.

Finally, we’ll consider the rotations of the edge cubies. Each edge cubie can be rotated in 2 possible ways, as you can see below. Like the corner cubies, the rotation of 1 edge piece is determined by the other 11, which can rotate freely. This leaves us with 211 possible edge rotations.

Complete Edge rotation demo

Now we multiply everything together:

8! x 37 x (12!/2) x 211

= 43,252,003,274,489,856,000 possible configurations.

That’s 43.25 quintillion. To put that in perspective, if you were to cover the ground in the same number of 1mm3 cubes, like in the picture below, you could almost cover the entire continent of Asia.

1mm cubed

If we want to find out how many possibilities there are if the cube is disassembled and reassembled in every possible way, we just need to remove the limitations of the cube that we took into account before.

8! x 38 x 12! x 212

= 519,024,039,293,878,272,000

With 519 quintillion 1mm3 cubes, we could cover the Earth once and almost the whole of the USA a second time.

Keep in mind that these combinations are only for the 3x3x3 cube. The world’s largest cube to date is 17x17x17, and it looks like this.


If we go through similar steps to reach the number of possible configurations on this cube, we arrive at approximately 6.69 x 101054. I can’t really put this number in perspective, seeing as the estimated number of atoms in the observable universe is 1082 at most.

A short while later I was fiddling around with the cube, and noticed that when I repeated a set of moves over and over, the cube returned to the state it was in when I started. This is true for any repeating set of moves that you can think of – the cube will always return to how it was when you began performing the moves. You can try it now if you have a cube.

The reason this works is because you can always return to a cube’s previous state by doing the inverse of the move you just did. For example, if you turn the top slice 90° to the left, you can get back to how it was by turning the same slice 90° to the right. For this reason, if you repeat one set of moves, you can’t get enter a loop other than the one you’re already in. Paul Taylor illustrates this well in his post:

impossible loop

If you had the cube at the top of the loop, you do the inverse of the set of moves you just performed. But which state does the cube return to? When repeating a single set of moves, a certain state can only be reached in one way. Therefore, a loop within a loop is not possible.

In a moment, I’m going to use standard Rubik’s Cube notation to describe certain moves. Each letter refers to one slice. The letters I’m going to use are F, B, L, R, U, D, E, M and S. Whenever I use a letter, it means I am turning that slice 90° clockwise. If there’s an apostrophe after a letter, such as F’, it means the slice is turned counter-clockwise.

The picture below will show you. If you’re still confused, look at this visual guide.


I soon noticed that the number of times I needed to repeat different sets of moves to return the cube to its original state varied greatly. A two-move set, consisting of L U, has to be repeated 105 times to return to its original state. However, an eight-move set, which is U R U’ L’ U R’ U’ L, only needs to be repeated 3 times. This led to my main question:

How do I determine how many times I need to repeat a move set to return the cube to its original state?

I looked online for any information surrounding this phenomenon, but the search was pretty fruitless. The only related article I found was the one I mentioned earlier: Paul Taylor’s ‘How to solve a Rubik’s cube in one easy step’. It tackles the problem of the maximum number of times you would need to repeat a move set to get to the cube’s original state. I found it very interesting; I certainly recommend you read it. He tackled the problem in an elaborate way, however, having to include some simple programming in order to reach a solution. I wanted to be able to find the required number of repetitions by only having to look at the cube.

Having found nothing to answer my particular query, I set out to look for an answer myself. I first reasoned that the solution was likely to include lowest common multiples, seeing as each cubie has its own individual cycle and it was only a matter of aligning all of the cycles. Secondly, I noticed that with every repeating set of moves, the cube would reach one of three states before it returned to its initial solved state:

'Cross' pattern

‘Cross’ pattern

'X' pattern

‘X’ pattern

'Circle' pattern

‘Circle’ pattern

Armed with these two observations, and a little free time, I eventually came up with a method for determining how many times a set of moves needs to be repeated in order for the cube to return to its original state. I’ll show you in a step-by-step guide, as this is the easiest way to explain it. The main instructions are in bold, with explanations written normally.

Step 1

Pick any set of moves to repeat.

Remember the set of moves – if you forget midway, you won’t be able to complete the process.

Step 2

Starting with a solved cube, perform the set of moves repeatedly.

Count how many repetitions you have done.

Keep repeating the set until your cube reaches one of the three states I pictured above: Cross, X, or Circle.

It’s possible that you’ll get back to the solved cube before you reach any of these states. This only happens with a few move sets, when the number of repetitions required is very low.

Step 3

When you get to one of the three states, you’ll notice that only one of the three types of cubies are out of place.

  • With the Cross pattern, only the corner cubies will be out of place.
  • With the X pattern, only the edge cubies will be out of place.
  • With the Circle pattern, only the centre cubies will be out of place.

Now you’ll need to find the lengths of all the cycles within the cubies that are out of place. What I mean by this is that one cubie is in the place of another cubie, which is in the place of another cubie, etc. If you trace back through where each cubie is supposed to go, you’ll reach the cubie you started at.

Here’s an example:

cycle demo

You can start at cubie 1, and see that it should go where cubie 2 is. You can then see that cubie 2 should go where cubie 3 is. Finally, you can see that cubie 3 should go where cubie 1 is, thus completing the cycle. This cycle would have a length of 3.

Once you’ve found the length of one cycle, you need to look at a cubie that wasn’t included in the cycle you just found. Start finding another cycle from that cubie, and find the length of that cycle. Continue this process until every cubie has been included in one cycle.

If a cubie is in the correct position but the wrong rotation, it still counts as a cycle. This problem only occurs with corner and edge cubies, not centres.

Corner rotation demo 1

If a corner cubie is rotated within itself, it counts as a cycle of 3.

Edge rotation demo

If an edge cubie is rotated within itself, it counts as a cycle of 2.

You should now have all the lengths of the cycles.

Step 4

Find the lowest common multiple (LCM) of all of the cycle lengths.

In case you’re not sure how, first you must split each number into its prime factors. For example:

6   = 2 x 3

8   = 23

10 = 2 x 5

Then select the highest powers of each different prime.

6   = 2 x 3

8   = 23

10 = 2 x 5

Finally, multiply all of the highest powers together.

LCM of 6, 8 and 10 = 23 x 3 x 5 = 120

Step 5

Multiply the LCM of the cycles by the number of repetitions you have made so far.

In Step 2, you will have counted how many times you repeated the set of moves to get to one of the three states. Simply multiply this by the LCM of the cycles you calculated in Step 4, and you’ll get the total number of repetitions required to return the cube to its original state.


For any repeating set of moves:

R = cn


R = number of repetitions required to return cube to original state

c = lowest common multiple of cycle lengths

n = number of repetitions performed to reach one of the states

Note: There is one type of scenario where this algorithm does not work. If the cross pattern is reached first, number of cycles is even and all cycles are 3, assume the lowest common multiple of the cycle lengths (c) is 9. 

In any instance where the algorithm doesn’t work, when the predicted number of repetitions is reached, all corner pieces are in the correct position, but the wrong rotation. The predicted number of repetitions must be repeated twice more to reach the correct rotations for all of the corner pieces.

If you have any ideas or comments on this algorithm, please don’t hesitate to contact me.


Finally, one more interesting feature of repeating move sets is that if you have a move set of length 2, you can double the length of the move set to 4, invert the repeated moves, and the resulting move set will, when repeated, return he cube to its original state in fewer repetitions than the first move set of length 2. In simpler terms, it is a move set in the form A B A’ B’. These move sets are called commutators, and the reason they can complete a cycle in fewer moves is because they return most cubies to their original position with each repetition. Only a few cubies are moved out of place.

This property is particularly useful for towards the end of the solving process, as only a few cubies may be out of place, and you don’t want to mess the rest of the cube up. In fact, the final algorithm for the Beginner’s method is R’ D R D’, which rotates the corner cubies within themselves. It is repeated until all of the corner cubies are in the correct rotation, at which point the cube is solved.

You can also merge commutators for interesting effects. Another common algorithm is U R U’ L’ U R’ U’ L, a combination of U R U’ R’ and U’ L’ U L, which swaps the positions of three corner cubies and keeps the fourth in place. The two separate move sets each need 6 repetitions to return the cube to its original state, while the combined move set requires 3 repetitions. The total number of individual moves is equal in all three cases.

Thank you for reading.

-Ollie James