15 Puzzle Solver
Enter your 15-puzzle, see instantly if it can be solved, and get the optimal solution.
What counts as a normal 15-puzzle answer?
Our earlier 200-board measured benchmark had shortest lengths from 42 to 64 single-tile moves; its middle half was 49–56, and its median was 53. This is a finite sample of solvable random arrangements, not the distance of every puzzle or a measure of human performance. The standard goal's proven hardest distance is 80 single-tile moves. A board created with only a few slides from the goal can need far fewer, and a returned fast route can be longer than its eventual certified answer.
Practical tips for this board
- Keep tiles 1–4 in reading order while retaining blank access beneath them.
- Treat tiles 3 and 4 as a pair near the end of the first row instead of placing 4 too early.
- Before solving a final two-tile reversal, check the blank position and parity against the intended goal.
- During playback, use the explanation for the current state rather than subtracting moves you made on a different physical board.
The classic 15-puzzle, solved optimally
The 15-puzzle is the original sliding puzzle: a 4x4 frame with tiles numbered 1 to 15 and one empty square. Slide the tiles until they read 1 to 15 in order, with the gap in the bottom-right corner. This 15 puzzle solver finds the fewest moves for any position you enter and plays them back one tile at a time. For other sizes, use the main sliding puzzle solver.
Press Load Sam Loyd's 14-15 puzzle above to see the most famous impossible position in history.
A short history
The puzzle was invented in the 1870s by Noyes Chapman, a postmaster in upstate New York, and became a worldwide craze in 1880. People played it in offices, on trains and in parliament. Puzzle maker Sam Loyd later claimed he had invented it and offered a $1,000 prize to anyone who could solve a board with only the 14 and 15 tiles swapped. Nobody ever collected, because that position can't be solved. Mathematicians had already proved in 1879 that exactly half of all 15-puzzle arrangements are impossible.
Why some 15 puzzles are unsolvable
Every slide keeps a hidden quantity called parity the same, so you can tell whether a position can be solved without searching. For a 4x4 board with the goal gap in the bottom-right:
- Read the tiles row by row, ignoring the gap, and count the inversions, every pair where a larger number comes before a smaller one.
- Find the row of the gap, counting from the bottom (bottom row = 1).
- Add the two numbers. If the sum is odd, the puzzle is solvable. If it's even, it isn't.
Check the solved board: 0 inversions plus the gap in row 1 gives 1, which is odd, so it's solvable. Swap 14 and 15 and you get 1 inversion plus row 1, which is 2. Even, so Loyd's puzzle is impossible. On boards with an odd width, like 3x3 or 5x5, the gap's row doesn't matter. The puzzle is solvable when the inversion count is even.
Swapping any two tiles flips the parity. That's why the solver's Fix it button only has to swap one pair of neighbors to turn an impossible board into a solvable one.
How the solver finds the fewest moves
There are 16!/2, more than 10 trillion, solvable 15-puzzle positions, far too many to store. Instead the solver uses IDA*, a search that increases a cost bound using admissible distance estimates and proves the shortest path when it completes. A pattern database tells it the least number of moves each group of tiles still needs. Together they find the optimal solution for almost any position within a second or two, right in your browser. The very hardest positions take much longer. An 80-move board takes about one to two minutes on a desktop computer and several minutes — ten minutes or more on slower phones, and the solver shows its progress while it works. Times vary with the device, temperature and other activity.
Moves are counted as single-tile slides (one tile moving into the empty space), the standard way optimal solutions are measured:
- Most moves any position needs: 80 (only 17 positions need that many)
- Average position: about 53 moves
- Typical hand solution with the row-by-row method: 100 to 150 moves
Using a picture instead of numbers?
For 4x4 picture puzzles, use the 4x4 Sliding Puzzle Solver. It lets you upload your image and shows which number each piece stands for.
When is the solution proven shortest?
The 4x4 solver can return a Fast solution first, then continue searching for a shorter path in the background. The fast count is the length of a valid sequence, not a proof of the minimum. When the heading becomes Optimal solution, exact search has completed and the displayed number is the shortest solution for the entered start and goal, counted in single-tile slides.
Choosing Show the quick solution now lets you follow the available route while exact search continues. Pressing Stop ends that search and retains an available fast answer. Stopping is not proof that no shorter route exists. A lower bound means that every solution requires at least that many moves; it does not tell you the complete route.
A verified three-move 15-puzzle solution
1 2 3 4
5 6 7 8
9 0 11 12
13 10 14 15
Load this exact starting board and press Solve. Slide 10 up, 14 left, then 15 left: 10 ↑, 14 ←, 15 ←. These are three single-tile moves to the ascending goal with the gap at bottom-right. The gap moves in the opposite direction from each tile.
The production IDA* search returns a length of three, and replaying the three legal slides reaches the goal. Tiles 10, 14 and 15 each start one cell from their target; their Manhattan distance sums to three. Since one slide can reduce that sum by at most one, no route of fewer than three moves exists. The matching path and lower bound make this example independently checkable.
The 15-puzzle walkthrough explains entering the board, verifying parity and following this sequence. The unsolvable-board guide contrasts it with the impossible 14-15 swap.
What the algorithms establish
3x3 boards use an exact breadth-first distance table. This 4x4 solver uses iterative deepening A* with admissible distance estimates and additive pattern databases. It searches successive cost bounds until a solution is found, which certifies the shortest path at completion. The fast row-and-column method is a separate source of a legal answer; it does not carry that certificate. The 5x5 solver and larger boards use the fast method without a shortest-path guarantee.
For the mathematical background, see the University of Alberta sliding-tile notes. The examples above were verified against this site's search and replay functions, using the explicitly shown start and goal.
Frequently asked questions
Can every 15 puzzle be solved?
No. Exactly half of all arrangements of the 15 tiles are impossible. The solver tells you immediately, and the Fix it button swaps two neighboring tiles to make the board solvable.
What is the most moves a 15 puzzle can need?
80. Every solvable 15-puzzle can be finished in 80 single-tile moves or fewer, and only 17 positions need all 80. An average random position needs about 53.
Does a 60-move fast answer prove the puzzle needs 60 moves?
No. It describes one legal route. Only a completed Optimal answer certifies the shortest count.
Can my target leave the blank at top-left?
Yes. Enter that arrangement through More → Edit goal. The result and solvability check are for the selected goal, not automatically the standard bottom-right blank.