Science Lab · Math and puzzles

Cube Solver

Paint in the colors of your own 2×2, 3×3 or 4×4 twisty puzzle cube, and the solver works out the moves and plays them on a 3-D cube, one turn at a time. It checks your colors first and explains anything that can't be right. Below it: how to read the moves, the beginner method step by step with practice cases, the common algorithms, why some cubes can't be solved, how many positions there are, and a timer.

Paint with

Painting with white. Tap a sticker on the 3-D cube or on the map below. Keys 1 to 6 pick a color, 0 the eraser, Z undoes.

Start from

Set it up from a list of moves

Check

Your cube's colors

The map is the cube unfolded: U top, L left, F front, R right, B back, D bottom. Each side is drawn as you'd see it looking straight at it, with the top side up (the top is drawn with the back edge up, the bottom with the front edge up).

How to use the solver

1. Pick the size. 2×2, 3×3 or 4×4. The 3×3 is the cube often sold as the Rubik's Cube. Each size remembers its own colors in this browser.

2. Paint the colors. Choose a color, then tap stickers on the map or on the 3-D cube. One face at a time walks you around your cube and tells you how to hold it for each side, so the map matches the real thing. On a 3×3, start from Centers only if your centers are white on top and green in front.

3. Read the check. It runs as you paint. A cube with a wrong sticker can't be solved, so the check looks for every kind of mistake: the wrong number of a color, two colors that can't share a piece, a piece that appears twice, a twisted corner, a flipped edge, and two pieces swapped. Show outlines the stickers involved.

4. Solve and follow along. On the 3×3, choose the fewest moves (about 20) or the beginner method (about 160, in steps you can learn). Play the moves, step through them, slow them down, and print the list to keep next to you.

Reading the moves

Every move is a letter for one side of the cube, seen with the cube held still in front of you:

LetterSideLetterSide
UUp: the topDDown: the bottom
RRightLLeft
FFront: facing youBBack
  • A letter alone, like R, is a quarter turn clockwise, as you would see it if you looked straight at that side. So R lifts the front of the right side up, and L pushes the front of the left side down.
  • A mark after the letter, R′ (said "R prime"), is a quarter turn counterclockwise: the same turn undone.
  • A 2, as in R2, is a half turn. Either direction gives the same result.
  • On big cubes, a w means wide: Rw turns the right face together with the layer next to it.
  • x, y and z turn the whole cube in your hands, the same way as R, U and F. The beginner solution uses y to bring the part you're working on to the front.
  • On a 3×3, M, E and S turn a middle layer. The solver doesn't use them, but you'll see them in other guides.

How to hold the cube

Hold it in both hands, thumbs in front, fingers behind. Keep the same side toward you and the same side on top for a whole list of moves: if the cube turns in your hands, every letter after that points at a different side. Turn the right side with your right hand and the left side with your left. For U, push the top front edge to the left with your right index finger; for U′, the other way. When you scramble a 3×3 the usual way to hold it is white on top and green in front.

Press a move to see it. The yellow arrow shows which way the layer turns.

The beginner method, step by step

This is the way most people first learn to solve a 3×3, and it is what Solve: beginner method uses. You solve the cube in layers: the bottom layer, then the middle, then the top. It takes about 160 turns, and you only need to remember a handful of short algorithms. Hold the cube with white on the bottom for every step. Each Practice button sets up a cube with the earlier steps done, so you can work on just that step, on the screen or on your own cube.

  1. The white cross

    Put the four white edges around the white center, so each one's other color matches the center on its side. There's no algorithm to memorize: bring an edge to the bottom next to its center, white side down, and try not to undo the ones already there. Tip: look for an edge in the top layer, turn the top until its side color matches the center under it, then turn that side twice.

  2. The white corners

    Find a white corner in the top layer. Turn the whole cube so the corner's spot is at the bottom front right, and turn the top until the corner sits right above it. Then repeat R U R′ U′ until the corner drops in with white on the bottom. It takes 1, 3 or 5 times, and the cross stays put. If a white corner is stuck in the bottom in the wrong place, do R U R′ U′ once with it at the front right to lift it out.

  3. The middle layer

    Find a top edge with no yellow. Turn the top until its front color matches the center below it, so it makes an upside-down T. If its top color matches the right center, it goes right: U R U′ R′ U′ F′ U F. If it matches the left center, it goes left: U′ L′ U L U F U′ F′. If a middle edge is in the wrong place or flipped, put any yellow edge into its spot with the same algorithm, and it pops out.

  4. The yellow cross

    Look at the top. You'll see a dot, an L, a line or a cross of yellow edges. Hold an L pointing to the back and the left, or a line running left to right, and do F R U R′ U′ F′. From a dot, just do it: you'll get an L or a line, and then do it again. Don't worry about the corners yet.

  5. The yellow edges

    Turn the top until at least two yellow edges match the centers on their sides. If two side-by-side edges match, hold them at the back and the right, then do R U R′ U R U2 R′ U: it swaps the front and left edges. If the two matching edges are across from each other, do the algorithm once from anywhere and look again.

  6. Yellow corners into place

    A corner is "in place" when it sits between the three centers of its colors, even if it is turned the wrong way. Find one in place, hold it at the front right, top, and do U R U′ L′ U R′ U′ L. That moves the other three corners around; do it again if they still aren't in place. If none is in place, do it once from anywhere first.

  7. Turn the yellow corners

    Hold a corner that isn't yellow-up at the front right, top. Repeat R′ D′ R D until yellow faces up: 2 or 4 times. The bottom will look scrambled. That's normal. Now turn only the top (U) to bring the next wrong corner to the front right, and repeat. Don't turn the whole cube during this step. When all four are yellow-up, turn the top to finish. The bottom comes back on its own.

Common algorithms

An algorithm is a short list of moves with a known effect. Show plays it on the demo cube, starting from the case it fixes.

NameMovesWhat it doesPlay
Right-hand triggerR U R′ U′The building block of many algorithms. Six in a row bring the cube back to the start. The beginner method uses it to drop in the white corners.
Middle edge, rightU R U′ R′ U′ F′ U FMoves the front-top edge down into the front-right slot without disturbing the bottom layer.
Middle edge, leftU′ L′ U L U F U′ F′The mirror image: front-top edge into the front-left slot.
Yellow crossF R U R′ U′ F′Flips top edges: dot to L, L to line, line to cross.
SuneR U R′ U R U2 R′Turns three top corners, and moves the top pieces around. With a U after it, it swaps the front and left top edges, which is how the beginner method uses it.
Corner cycleU R U′ L′ U R′ U′ LMoves three top corners around in a cycle and leaves the front-right corner where it is.
Corner twisterR′ D′ R DDone twice, it twists the front-right top corner in place and scrambles the bottom a little. Done 6 times, it puts everything back.
Edge cycle (U perm)R U′ R U R U R U′ R′ U′ R2Moves three top edges around and nothing else. Speedcubers use it at the very end.
T permR U R′ U′ R′ F R2 U′ R′ U′ R U R′ F′Swaps two top corners and two top edges. It is one of the 21 "PLL" algorithms that finish the cube in faster methods.
CheckerboardR2 L2 U2 D2 F2 B2A pattern: every face becomes a checkerboard. Do it again to undo it.
SuperflipU R2 F B R B2 R U2 L B2 R U′ D′ R2 F R′ L B2 U2 F2Flips all 12 edges in place. It was the first position proved to need 20 moves.
4×4 OLL parityRw U2 x Rw U2 Rw U2 Rw′ U2 Lw U2 Rw′ U2 Rw U2 Rw′ U2 Rw′Flips one paired edge of a 4×4 (the front-top one), which a 3×3 can't do. It also swaps the top-left and top-right edges and the two front corners on top; the rest of the solve fixes those like any 3×3.
4×4 PLL parityRw2 F2 U2 Rw2 R2 U2 F2 Rw2Swaps the front-top and back-top edges of a 4×4 and nothing else a 3×3 would notice.

Why some cubes can't be solved

Take a 3×3 apart and put the pieces back at random, and only 1 time in 12 can it be solved by turning. Turning the faces can rearrange the pieces in many ways, but not in every way. Three rules always hold:

Corner twist. Give each corner a number for how it's turned: 0 if its white or yellow sticker faces up or down, 1 if it's turned one step clockwise from that, 2 for two steps. Every face turn keeps the total a multiple of 3. A cube with one corner twisted in place breaks that rule, so it can't be solved. Twisting that corner back by hand fixes it. In a random reassembly, this rule fails 2 times in 3.

Edge flip. In the same way, every turn flips edges in pairs, so the number of flipped edges is always even. One flipped edge can't be fixed by turning. In a random reassembly, this rule fails 1 time in 2.

Swap parity. Any rearrangement can be built from swaps of two pieces. A quarter turn moves 4 corners in a cycle (3 swaps) and 4 edges in a cycle (3 swaps), 6 swaps in all, an even number. So the total number of swaps is always even, and a cube with just two pieces swapped can't be solved. This rule also fails 1 time in 2.

3 × 2 × 2 = 12, so 11 of every 12 random reassemblies are stuck. When the check finds one of these, it usually means a sticker was entered wrong. If every sticker is right, someone took the cube apart, twisted a corner or peeled a sticker. Taking out pieces and putting them back the right way fixes it.

Try it: each button loads a scrambled 3×3 with one thing broken, and the check explains it.

Parity on the 4×4

A 4×4 has no fixed centers, and each edge is really two pieces. Its inner layers can make an odd number of swaps of edge pieces, which a 3×3 never can. So after pairing the edges, the cube sometimes looks like a 3×3 with one flipped edge (called OLL parity) or two swapped edges (PLL parity). Neither is a mistake. Each has its own algorithm, shown above, and the solver adds them when needed. The 2×2 has no such problems: any turn of its corners is possible except a single twisted corner.

How many positions?

CubePositions you can reach by turningWhere the number comes from
2×23,674,160Hold one corner still: 7! ways to arrange the other corners × 36 ways to twist them (the last twist is forced).
3×343,252,003,274,489,856,000
(about 43 quintillion)
8! × 37 for the corners, × 12! × 211 for the edges, ÷ 2 because the swaps must be even.
4×47,401,196,841,564,901,869,874,093,974,498,574,336,000,000,000
(about 7.4 × 1045)
7! × 36 for the corners, × 24! for the edge pieces, × 24! ÷ (4!)6 for the centers, since the 4 centers of a color look alike.

If you could look at a billion 3×3 positions every second, seeing them all would take over 1,300 years. Taking a 3×3 apart and reassembling it gives 12 times as many arrangements, 519,024,039,293,878,272,000, but only one in 12 is in the list above.

God's number

What is the fewest moves that always works, from the very worst position? In 2010, Tomas Rokicki, Herbert Kociemba, Morley Davidson and John Dethridge proved that every 3×3 position can be solved in 20 moves or fewer, counting a half turn as one move, and that some positions need all 20. The superflip above is one of them. They split the positions into about 2.2 billion groups, used the cube's symmetry to cut that to about 56 million, and solved each one with a fast program, using about 35 years of computer time. Counting only quarter turns, the answer is 26, proved in 2014. For the 2×2 it is 11, and this page's solver checks that number itself: the table below is the count it makes of every 2×2 position by distance.

Moves01234567891011
2×2 positions19543211,8479,99250,136227,536870,0721,887,748623,8002,644

Half-turn metric, with one corner held still. The numbers add up to 3,674,160.

Scramble and time yourself

…

0.00

Scramble your cube with the moves above (white on top, green in front). Then press and hold Space (or hold the timer) until it turns green, and let go to start. Any key or a tap stops it.

    The averages work like competitions: of your last 5 (or 12) solves, the best and worst are dropped and the rest averaged. A DNF counts as the worst. The 2×2 and 3×3 scrambles are random positions, every one equally likely; the 4×4 uses 40 random turns. Times are saved in this browser only.

    How the solver works

    2×2: the shortest answer. Holding one corner still leaves 3,674,160 positions, few enough to list them all. When the page first solves a 2×2, it works out the exact distance of every position from solved (a breadth-first search, under a second). From your position it then always takes a turn that brings it one step closer, so the answer is as short as possible.

    3×3: the two-phase method. Herbert Kociemba's 1992 idea. Phase 1 turns the cube until no corner is twisted, no edge is flipped and the four middle edges are in the middle layer. From there, only U, D and half turns of the sides are needed, and phase 2 finishes with just those. Both phases search with tables that give a lower bound on how many moves are left, so hopeless paths are dropped early. It keeps looking for shorter solutions for up to 1.5 seconds and stops at 20 moves.

    3×3: the beginner method. The same steps a person learns, done by the computer: a small search places each cross edge, then the standard algorithms from the guide above do the rest, with whole-cube turns so every algorithm is done from the same hold.

    4×4: reduction. First the centers, in three searches over where the center colors sit, each with an exact distance table. Then the edges: a wide turn brings two matching pieces together, three outer turns swap the new pair out of the way, and the wide turn is undone; a search picks the best of these each time. Then any parity fix, and a two-phase 3×3 solve that turns only the outer layers.

    The searches run in a background worker, so the page doesn't freeze. The first solve of each size builds its tables, which takes a moment.

    How it was checked

    TestResult
    2×2: 3,000 random positions, every solution applied to the cubeall solved; length matches the distance table (at most 11)
    2×2: count of positions by distance1, 9, 54, … 2,644 (table above), total 3,674,160
    3×3 fewest moves: 2,000 random positionsall solved; median 20 moves, longest 22 (85% in 20 or fewer); median 0.08 s, slowest 1.5 s
    3×3 beginner method: 2,000 random positions, in random orientationsall solved; median 160 turns, longest 223
    4×4 reduction: 1,000 random scrambles (100 random turns each)all solved; median 84 turns, longest 110; median 0.2 s, slowest 1.1 s
    Broken cubes: a twisted corner, a mirror-image corner and one wrong sticker (1,200 of each across the three sizes); a flipped edge and two swapped edges (400 of each on the 3×3); a 4×4 edge piece with its stickers swapped (400)every one caught, with the right reason
    Position counts aboveworked out exactly with whole-number arithmetic

    Sources

    @teddyrookbook GitHub