Skip to content

How to Solve Any Sliding Puzzle: The Layer Method

The 15 puzzle looks like trial and error. It is not. Solve it in layers, learn one rotation trick, and every board becomes routine.

The sliding puzzle has been frustrating people since the 1880s, when the original 15 puzzle became a genuine international craze. The rules take one sentence. The solution takes a method, and without one you will shuffle tiles indefinitely, fixing one and breaking two.

Why intuition fails here

In most puzzles you can place a piece and leave it. Here you cannot. Every move you make to position one tile displaces another, and the empty square — the only thing you actually control — has to travel a loop of four or five moves just to approach a tile from a different side.

The consequence is that ad-hoc solving does not converge. You need a method where each step permanently finishes part of the board and never touches it again.

The layer method

The approach is to reduce the puzzle to a smaller puzzle, repeatedly.

  1. Solve the entire top row. Never disturb it again.
  2. Solve the entire left column of what remains. Never disturb it again.
  3. You now have a smaller square. Repeat from step 1 on it.
  4. Continue until only a 2 × 2 corner remains, which is solved by rotation.

On a 4 × 4 board that means: top row, left column, then a 3 × 3 sub-puzzle — top row, left column — then a final 2 × 2. Four phases, each simpler than the last.

Positioning a single tile

Within a phase, the basic operation is: bring tile X to square Y without breaking anything already finished.

The technique is always the same. Move the blank to the square adjacent to the tile, on the side you want the tile to travel toward, taking a route that avoids solved regions. Then swap them. Repeat.

Moving a tile one square typically costs a five-move loop of the blank: the blank has to go around the tile to get to its other side. Once you start counting in loops rather than in tile-moves, the move count becomes predictable and the puzzle stops feeling random.

The trick everyone gets stuck on: the last two of a row

Here is the situation that stops most people. You have solved the first two tiles of the top row. Only tiles 3 and 4 remain. You place tile 3 in its home square — and then discover there is no way to bring tile 4 into the corner without knocking tile 3 out.

This is not bad luck. It is structural, and there is a standard manoeuvre for it.

The rotation: instead of placing tile 3 in its own square, place tile 4 there. Then place tile 3 directly beneath it. You now have a vertical domino in the wrong place — but a single rotation of the blank around those two tiles drops both into their correct positions simultaneously.

Concretely, for the top-right corner of a 4 × 4:

  1. Put tile 4 into position 3 (the third square of the top row).
  2. Put tile 3 into the square directly below it.
  3. Bring the blank to the top-right corner.
  4. Rotate: the two tiles slide into place as a pair.

The identical logic applies to the last two tiles of a column, rotated ninety degrees. Learn this one manoeuvre and the puzzle becomes routine — it is the only genuinely non-obvious step in the entire method.

The final 2 × 2

Once everything but a 2 × 2 corner is solved, only three tiles and the blank remain, and the only legal moves cycle them. Rotate the cycle until they land. It takes at most a few moves, and if it will not resolve, the board was unsolvable to begin with — which brings us to parity.

Why you cannot just swap two tiles

Exactly half of all possible tile arrangements are unreachable from the solved state. That is not a limitation of your technique; it is arithmetic.

Every legal slide swaps the blank with one tile — a single transposition. Moving the blank around a loop and back to where it started always takes an even number of moves, which means the permutation's parity is conserved. A board that differs from the solution by exactly one swapped pair has odd parity and can never be solved, no matter how long you work at it.

This is precisely why the last-two-tiles rotation exists: it performs a three-cycle rather than a swap, which preserves parity.

Any well-built implementation, including this one, scrambles the board by making random legal moves from the solved state, which guarantees solvability. Physical puzzles with removable tiles have no such guarantee — the famous 19th-century version of the craze was built on a deliberately unsolvable arrangement.

Move counts, and what "good" means

BoardHardest possible positionTypical shuffle, played well
3 × 3 (8 puzzle)31 moves20–25
4 × 4 (15 puzzle)80 moves40–60
5 × 5 (24 puzzle)Believed 152 moves110–150

The layer method does not produce optimal solutions — finding those is computationally hard even for a 4 × 4 — but it produces a solution every time, in a number of moves within roughly 50% of optimal. That trade is worth it.

Practising it

Start on 3 × 3 until the layer method requires no thought. Move to 4 × 4 and expect the last-two-tiles rotation to be the only place you hesitate. Only then attempt 5 × 5, where the method matters most: a 5 × 5 solved by intuition is a genuinely miserable experience, and the same board solved by layers is simply long.

Try it yourself

The game this guide is about

More guides

How to Win 2048: The Corner Strategy, Step by Step

Almost every 2048 win is built on one habit. Here is the habit, why it works, and the three mistakes that undo it.

What Is a Good Reaction Time? A Look at the Actual Numbers

The human average sits near 250 milliseconds. Here is where that number comes from, what moves it, and how much of your score is you versus your hardware.

How to Type Faster: A Realistic Path from 40 to 100 WPM

Speed is a side effect of not making mistakes. The route from average to fast is mostly about unlearning three habits.