How to Solve a Sliding Puzzle: 3x3, 4x4 and 5x5 Step by Step
The method for every square sliding puzzle in two sentences, then spelled out move by move for the 3x3, 4x4 and 5x5: the stacked-pair trick, the parity check that spots an impossible board, and why Klotski needs a different plan.
To solve a sliding puzzle, finish the top row, then the row under it, and keep going until only two rows are left; finish those two rows one column at a time from the left, and the last 2×2 square solves itself when you walk the blank round it. The one trick you need is for the last two tiles of every row and column, which go in together as a stacked pair rather than one at a time.
That is the whole method, and it works on a 3×3, a 4×4 and a 5×5 alike. Below it is spelled out move by move, along with the parity check that tells you whether a board can be solved at all, and the different plan you need for Klotski and car-escape puzzles, where the pieces come in different sizes. If you are after general habits rather than a method, our sliding puzzle tips cover those.
The rules: one empty square, and half of all shuffles cannot be solved
A sliding tile puzzle is a square frame of numbered tiles with one space missing. You slide any tile next to the gap into it, and the goal is the tiles in order, left to right and top to bottom, with the gap in the bottom-right corner. The 3×3 version is the 8-puzzle, the 4×4 is the 15-puzzle and the 5×5 is the 24-puzzle, named for how many tiles they hold.
Prise the tiles out and put them back at random, and exactly half of the arrangements you could make can never be solved. Sliding never changes a hidden quantity called parity, and you can check it with a pencil. Read the tiles left to right, top to bottom, skipping the gap, and count every pair where a bigger number comes before a smaller one. Each such pair is an inversion.
- Odd widths (3×3, 5×5): the puzzle is solvable exactly when the number of inversions is even.
- Even widths (4×4): add the row the gap is in, counting rows 1 to 4 from the top. The puzzle is solvable exactly when that total is even. (Count rows from the bottom instead and you need an odd total. Same rule, other way up.)
A worked 3×3 example. Take the board 1 3 _ / 4 2 5 / 7 8 6, with the gap top right. Reading it out gives 1, 3, 4, 2, 5, 7, 8, 6. The inversions are 3 before 2, 4 before 2, 7 before 6 and 8 before 6: four, which is even, so it can be solved. It takes four moves: slide 3 right, 2 up, 5 left and 6 up. Now take a solved board and swap the 7 and the 8. That is one inversion, odd, and no sequence of slides will ever fix it.
The 4×4 version of that trap made the 15-puzzle famous. It was a craze in the United States in 1880, and the puzzle writer Sam Loyd publicised a $1,000 prize for anyone who could start from a solved board with the 14 and 15 swapped and put them right. One inversion, plus the gap in row 4, makes 5: odd, so impossible. The prize money was never at risk. Any decently built digital puzzle shuffles itself by making legal moves from a solved board, so the one on your screen has a solution. A physical one that a sibling has prised apart may not.
The 3×3 (8-puzzle) comes out in four stages
Rows are numbered from the top and columns from the left. “Lock” means that from then on the gap never passes through those squares.
- Tile 1 home. Walk the gap round to bring 1 into the top-left corner. Lock it.
- Tiles 2 and 3 as a stacked pair. Put 2 in the top-right corner (3’s square, not its own) and 3 directly underneath it, in row 2, column 3. Bring the gap to the top-middle square by way of row 2, never through the corner. Slide 2 left, then slide 3 up. Top row done. Lock it.
- Tiles 4 and 7 as a stacked pair, sideways. Put 7 in 4’s square (row 2, column 1) and 4 directly to its right, in the centre. Bring the gap to the bottom-left corner along the bottom row. Slide 7 down, then slide 4 left. Left column done. Lock it.
- Tiles 5, 6 and 8: rotate. What is left is a 2×2 square with three tiles and the gap. Walk the gap round it in one direction and the three tiles cycle until they land. It never takes more than six moves in the right direction; if the first lap goes nowhere, go the other way.
The reason for the stacked pair: if you put 2 home first, the only way for 3 to reach the corner runs through 2’s square, so placing 3 knocks 2 out. Stacking them first and rotating lands both in two slides. Most people try the one-at-a-time version several times before believing this. We tried it more than most.
The 4×4 (15-puzzle): two rows, two columns, then a rotation
The 15-puzzle is the same plan with one more stage. Solve row 1 (tiles 1 to 4) and row 2 (5 to 8) as rows, then the bottom two rows column by column: 9 and 13, then 10 and 14, then rotate 11, 12 and 15 home in the last 2×2. In each row the first two tiles are easy; walk them home one at a time. Only the last pair needs the trick.
The last two tiles of a row, move by move
Here it is for row 1, with tiles 1 and 2 already home and locked.
- Clear tile 4 out of the way first. If 4 is in row 1 or row 2, move it down to row 3 or lower. This stops it drifting into the wrong square in step 2.
- Put tile 3 in the top-right corner (row 1, column 4), which is 4’s square, not 3’s.
- Bring tile 4 to the square directly below it (row 2, column 4), moving only tiles in rows 2 to 4 so 3 stays in the corner.
- Bring the gap to row 2, column 3, beside tile 4, again without touching row 1. Then slide whatever tile is in row 1, column 3 down into the gap. The gap is now in 3’s square, with 3 to its right and 4 below 3.
- Slide 3 left. Slide 4 up. Row 1 is finished. Lock it.
Row 2 works the same way: 5 and 6 go in one at a time, then 7 into row 2, column 4, with 8 under it in row 3, column 4, the gap into row 2, column 3, and the same two slides: 7 left, 8 up.
The bottom two rows, one column at a time
With rows 1 and 2 locked, you have two rows of four left: 9, 10, 11, 12 above 13, 14, 15 and the gap. Rows would not work here because there is no spare row to park tiles in, so you go across in columns, using the same pair trick turned on its side.
- Column 1 (tiles 9 and 13). Put 13 in 9’s square (row 3, column 1) and 9 directly to its right (row 3, column 2). Bring the gap along row 4 to row 4, column 1. Slide 13 down, then 9 left. Lock the column.
- Column 2 (tiles 10 and 14). Same again one column over: 14 in row 3, column 2, 10 in row 3, column 3, gap to row 4, column 2. Slide 14 down, 10 left. Lock it.
- The last 2×2 (11, 12 and 15). Walk the gap round the square until all three land, exactly as on the 3×3. If the shuffle was legal, they will.
This method is reliable, not short. A computer searching for the shortest route never needs more than 80 single-tile moves on any 15-puzzle, and only 17 positions need all 80. Row by row takes more than that, but you can do it without stopping to think, and for a person that matters far more than the move count.
The 5×5 (24-puzzle) is a 4×4 with an extra row and column
Every bigger board peels down to the one below it. On a 5×5, solve row 1 (tiles 1 to 5, with 4 and 5 as the stacked pair), then the left column below it (6, 11, 16 and 21, with 16 and 21 as a sideways pair: 21 in 16’s square, 16 to its right, gap below, slide 21 down and 16 left). Lock both, and what is left is a 4×4 made of tiles 7 to 10, 12 to 15, 17 to 20 and 22 to 24. Solve that exactly as above, reading the numbers as positions rather than 1 to 15.
You can also just carry on row by row to row 3 and then do the bottom two rows in columns; both routes end in the same 2×2 rotation. The 5×5 has about 7.76×1024 reachable arrangements, and nobody has yet pinned down the most moves any of them needs. The most recent bounds we could find, from 2016, put it somewhere between 152 and 205 single-tile moves.
Klotski and car-escape puzzles need a different method
Row by row only works when every piece is the same size. Klotski, and the whole family of sliding-block puzzles it belongs to, mixes pieces of different shapes, and there is no row to finish because nothing has a numbered home. Only one piece matters: the one you are trying to get out.
The classic Klotski starting position is a 4×5 tray holding ten pieces: one big 2×2 block in the top middle, a 2×1 block lying flat under it, two small 1×1 squares under that, and down each side two upright 1×2 blocks with a 1×1 square at the bottom. The two empty squares sit together at the bottom middle. The goal is to get the 2×2 block to the bottom middle and out through the gap in the frame. In China the same puzzle is known as Huarong Dao, with the big block as the warlord Cao Cao making his escape, which is a lot of narrative for some wood.
- Plan the target piece’s route first. Trace the path the big block (or the escaping car) has to take to the exit, square by square, before you move anything.
- Work backwards from the exit. For the next step on that path, ask what has to be empty, which piece is in the way, and where that piece can go. Then ask the same of whatever is in its way. That chain is the real puzzle.
- Keep the two gaps together in Klotski. A 1×2 block can only move sideways into two empty squares side by side, and the big block always needs two. Splitting the gaps up strands half the pieces.
- Count moves as pieces moved, not squares. In Klotski, a piece sliding to any spot it can reach is one move, and by that count the classic start needs at least 81. A plan of “this block to the left wall” is easier to hold in your head than a list of single steps.
Sliding car puzzles, the Rush Hour family, add one more rule: every vehicle is locked to its own lane, so a car lying across the board can only go left and right. That makes the backwards chain even more useful, because each blocker has only a few places it could end up. We go further into reading a car puzzle from the exit in our tips post.
3x3 vs 4x4 vs 5x5 vs Klotski at a glance
| Puzzle | Board | Pieces | Empty squares | Solvable from a random layout | Most moves ever needed | Method |
|---|---|---|---|---|---|---|
| 8-puzzle | 3×3 | 8 numbered tiles | 1 | Half (181,440 positions) | 31 | Top row, then left column, rotate the last 2×2 |
| 15-puzzle | 4×4 | 15 numbered tiles | 1 | Half (10,461,394,944,000 positions) | 80 | Rows 1 and 2, then columns, rotate the last 2×2 |
| 24-puzzle | 5×5 | 24 numbered tiles | 1 | Half (about 7.76×1024 positions) | Not yet known (152 to 205) | Peel off a row and a column, then solve as a 4×4 |
| Klotski | 4×5 | 10 blocks in four sizes | 2 | Not a shuffle puzzle; the classic start is solvable | 81 for the classic start (one piece moved = one move) | Plan the big block’s route, work backwards |
| Car Parking (ours) | 6×6 | Cars and limos locked to their lanes | Varies by level | Every level checked by a solver | Par per level, the solver’s minimum | Work backwards from the exit |
Common mistakes that keep a board unsolved
- Placing the last two tiles of a row one at a time. The second always evicts the first. Stack them and rotate.
- Letting the gap wander back into a finished row. Every trip up there undoes work. If a route needs it, find another route.
- Doing the bottom two rows as rows. There is nowhere to park a tile. Switch to columns when two rows are left.
- Treating the last 2×2 as three separate tiles. It is one rotation. Go round, and if the first lap does nothing, go the other way.
- Miscounting parity. Do not count the gap as a tile, and on a 4×4 do not forget to add the gap’s row.
- Splitting the two gaps in Klotski. The larger blocks need both of them side by side to move at all.
Where to play: our sliding-block game is a car puzzle, not a 15-puzzle
We do not make a numbered 15-puzzle, so for the tile method above you will want a physical one or any tile-slider app. What we do make is Car Parking, a free browser game from the Klotski and Rush Hour side of the family: a 6×6 car park, a gold car boxed in by traffic, and every vehicle locked to its own lane. A move is one vehicle parking somewhere new, however far it slid, and each of the 240 levels shows a par that is the shortest solution our solver found. There is unlimited undo and three hints a level, and no download or sign-up.
Its limitation for this post: it practises the backwards-from-the-exit method, not the row-by-row one, and progress is saved in your browser, so clearing site data resets it. Our other sliding game, Getaway Garage, moves every vehicle at once with each swipe and clears matching threes, which makes it a different puzzle again. If you want to know where these puzzles came from, our history of traffic jam puzzles starts with the 15-puzzle craze.
The decision rule is short. If every piece is the same size, finish rows from the top, switch to columns for the last two rows and rotate the final square. If the pieces differ, pick the one piece that has to escape and plan backwards from the exit. Car Parking is free in your browser if you want to try the second method on a board with a par to beat.
Frequently asked questions
How do you solve a 4x4 sliding puzzle?
Solve the top row, then the second row, never disturbing a finished row. For the last two tiles of each row, put the third tile in the corner and the fourth directly below it, bring the gap next to the corner, then slide the third tile left and the fourth up. Finish the bottom two rows one column at a time from the left with the same trick turned sideways, then walk the gap round the last 2×2 until 11, 12 and 15 land.
How do you solve a sliding puzzle?
Work row by row from the top until two rows are left, then column by column from the left, and finish by rotating the last 2×2 square. Place the last two tiles of each row or column together as a stacked pair rather than one at a time. The same method works on 3×3, 4×4 and 5×5 boards.
Is every sliding puzzle solvable?
No. Exactly half of all random arrangements cannot be solved. Count inversions, the pairs where a bigger number comes before a smaller one when you read the tiles in order. On a 3×3 or 5×5 the puzzle is solvable when that count is even. On a 4×4 add the gap’s row counted from the top (1 to 4); the puzzle is solvable when the total is even. A puzzle that was shuffled by sliding from a solved state is always solvable.
What is the fastest way to solve a sliding puzzle?
For a person, the row-by-row method with the stacked-pair trick: it is not the shortest route, but it needs no stopping to think. The shortest possible solution for a given board is found by computer search, which is too slow to do in your head.
How many moves does a 15-puzzle take?
Any solvable 15-puzzle can be solved in 80 single-tile moves or fewer, and only 17 positions need all 80. If sliding a whole line of tiles at once counts as one move, the maximum is 43. The 3×3 8-puzzle never needs more than 31 single-tile moves. The row-by-row method takes more moves than the optimum but is far easier to follow.
What is a Klotski puzzle?
Klotski is a sliding-block puzzle on a 4×5 board with ten blocks of four sizes and two empty squares. In the classic starting position a large 2×2 block sits at the top middle, and the goal is to slide it to the bottom middle and out of the frame. The classic start needs at least 81 moves, counting each piece slid to a new spot as one move.
How do you solve a sliding car puzzle?
Start at the exit and work backwards. Find the vehicle blocking the escaping car, work out where it would have to go, then find what is blocking that spot, and so on until you reach a vehicle that can move. Each vehicle only moves along its own lane, so there are few places it can end up. You can practise on our free browser game Car Parking, where every level has a solver-checked par.


