How to Solve a Sliding Tile Puzzle, Step by Step
This article was written with AI and may contain mistakes. Found one? Tell us.
To solve a sliding tile puzzle, finish the top row first, then the left column, and then treat what is left as a smaller puzzle and repeat. The only tricky part is the last two tiles of each row or column, and there is a simple move pattern for that, shown below.
This guide works for the 3 by 3 puzzle with 8 tiles, the 4 by 4 puzzle with 15 tiles, and any larger tray. A practice position waits at the end.
What is a sliding tile puzzle?
A sliding tile puzzle is a square tray of numbered tiles with one empty space. You slide a tile next to the space into it, one move at a time, until the tiles are back in order with the space in the last corner [1]. The 4 by 4 version is called the 15-puzzle and the 3 by 3 version the 8-puzzle. The general version on a tray of side n is called the (n² − 1)-puzzle [1].
The 15-puzzle is said to date back to the 1870s [1].
The idea behind the method
Moving one tile almost always disturbs others. The trick is to lock tiles into place in an order where you never need to touch them again.
That is why the method works row by row and column by column. Once the whole top row is right, you never need it again. Once the left column is right too, the rest of the tray behaves like a smaller puzzle with one less row and one less column [1]. A 4 by 4 tray becomes a 3 by 3 puzzle, and a 3 by 3 tray becomes a 2 by 2 puzzle that you can finish by turning the last three tiles round in a circle.
Step 1: move the space, not the tile
Beginners often chase a tile. It is easier to think about the empty space. To move a tile, first bring the space next to it, on the side you want the tile to go. Then slide the tile into the space.
To move a tile several steps, repeat a small loop. There are short patterns of five moves that shift a tile one place sideways or up and down, and a pattern of six moves that shifts it one place diagonally [1]. In practice, the loop is: slide the tile into the space, then walk the space round the tile to its other side, and slide it again.
Step 2: build the top row, except the last two tiles
Bring tile 1 to the top left corner. Then bring tile 2 next to it, and so on along the row, taking care not to disturb the tiles you have already placed [1]. On a 4 by 4 tray, that means placing 1 and 2 normally.
Keep the space below the row while you work. If the space has to pass through the top row, you will knock a placed tile out.
Step 3: the last two tiles of the row
The last two tiles need a few extra moves to flip into place [1]. Here is the pattern for a 4 by 4 tray, where tiles 3 and 4 finish the top row:
- Move tile 4 into the spot where tile 3 belongs, in the top row.
- Move tile 3 into the space directly below tile 4.
- Bring the empty space to the top right corner, where tile 4 belongs, without moving tiles 1 and 2.
- Slide tile 4 right into the corner.
- Slide tile 3 up into its place.
In other words, you park the pair one step early, then swing them in together. The same trick works for the last two tiles of any row on any tray.
If tile 4 is stuck in the top right corner while tile 3 is somewhere else, move tile 4 out of the corner first, down and away, and then follow the pattern.
Step 4: build the left column
Do the same down the left column. Place each tile from the top down, and use the same park and swing trick for the last two tiles, turned on its side: park the bottom tile in the spot of the one above it, put the other tile beside it, then swing them in.
Step 5: repeat on the smaller puzzle
With the top row and left column finished, ignore them. What remains is a smaller tray, and you solve it the same way [1]. On a 4 by 4 tray, you are now doing a 3 by 3 puzzle. Solve its top row and left column, and you are left with a 2 by 2 corner holding three tiles and the space.
Step 6: finish the last corner
In the final 2 by 2 corner, the space can only move round in a circle. Keep moving it round until the three tiles line up in order. If they never line up, recheck the rows and columns you finished earlier, and make sure the tiles were not taken out and put back in a different order.
Worked example: a whole 8-puzzle
Here is a full solve that uses every step. The dash is the empty space.
| 1 | 3 | 5 |
| 4 | 2 | 6 |
| 7 | 8 | – |
Top row. Tile 1 is already in its corner, so the last two tiles of the row are 2 and 3. Look at where they sit: tile 3 is in the spot where 2 belongs, and tile 2 is directly below it. That is exactly the parked position from Step 3, so no setup is needed.
Next, bring the space to the top right corner without touching tile 1. Slide 6 down, then slide 5 down. The space is now in the corner where 3 belongs.
Now swing the pair in. Slide 3 right into the corner, then slide 2 up into its place. The top row reads 1 2 3.
Left column. Tiles 4 and 7 are already in place, so there is nothing to do.
Last corner. The 2 by 2 corner holds 5, 6, 8 and the space. Slide 5 left and 6 up, and the tray reads 1 2 3, 4 5 6, 7 8, with the space in the last corner.
That is six moves in all. Real puzzles rarely start this kindly, but the order of work is always the same: park, swing, and move on.
How many moves does a puzzle take?
For small trays, the true minimum is known. The 3-tile puzzle on a 2 by 2 tray never needs more than 6 moves, the 8-puzzle never needs more than 31 and the 15-puzzle never needs more than 80 [1].
For large trays, finding the shortest solution is very hard. It has been proved that finding the minimum number of moves for the general puzzle is NP-hard [1]. That is why the row and column method does not even try to find the shortest solution. It always works, and it is quick to learn.
How fast is it? A 2015 paper worked out that this method, called the greedy method because it fixes one tile at a time, makes on average about 8/3 n³ moves on a tray of side n [1]. The author checked the formula by solving 10,000 random positions for every size from 4 to 200 [1]. So doubling the side of the tray makes the method's work roughly eight times longer.
Why not let a computer search instead?
Computers can solve puzzles by searching through every arrangement, but the numbers grow fast. One well-known search settled whether 24 squares of different sizes fit inside one larger square, and it checked about 375 million partial arrangements to do it [2]. A simple step-by-step method avoids that kind of search, which is why it is the one people use by hand.
How do you get faster?
Speed comes from planning the space's route before you move anything. Before each tile, look at where the space is, where the tile is and where it must go, and pick the shortest loop round the tile that stays clear of finished rows.
It also helps to say the moves to yourself as directions, such as down, left, up, rather than thinking about tile numbers. After a few solves, the five-move loop and the park and swing trick start to feel like single moves, and the whole method runs much more smoothly.
Common mistakes to avoid
- Placing the last tile of a row directly. It almost always knocks out the tile next to it. Use the park and swing trick.
- Letting the space wander into finished rows. Plan a route for the space that stays inside the unfinished part.
- Chasing a tile instead of moving the space. Think about where the space needs to be before each slide.
- Working in a different order every time. Always row first, then column. Repeating the same order makes the moves automatic.
Practice position
Here is an 8-puzzle to try. The dash is the empty space.
| 4 | 1 | 3 |
| – | 2 | 6 |
| 7 | 5 | 8 |
Can you solve it in 5 moves? Try it before you read on.
Answer: slide 4 down, 1 left, 2 up, 5 up and 8 left. The tray then reads 1 2 3, 4 5 6, 7 8, with the space in the last corner.
When you have that one, try a picture riddle that also asks you to plan moves in your head:
References
- Parberry, I. (2015, July 10). Solving the (n² − 1)-Puzzle with 8/3 n³ Expected Moves. Algorithms, 8(3), 459-465. DOI 10.3390/a8030459
- Laverty, B., & Murphy, T. (2018, September 25). Optimal Rectangle Packing for the 70 Square. Recreational Mathematics Magazine, 5(9), 5-47. DOI 10.2478/rmm-2018-0001