A 5x5 sliding puzzle is solved by reduction: build the top two rows, then the next row and a half, then finish the remaining 2×3 block with a small set of cycling moves. There is no single formula that unscrambles all 24 tiles at once; a working algorithm is a layered procedure that creates a solved region and never disturbs it.
The 5×5 version—often called a 24-puzzle—adds one more row and column than the familiar 15-puzzle, but the same staged logic applies, with a few extra edge cases that trip people up.
This guide explains the layered method, the techniques for each stage, the parity trap that can make a scrambled board unsolvable, and the alternative algorithmic approaches (IDA* and pattern databases) used when you want a computer to find a shortest solution. Whether you're a child working a physical 5x5 slider or a programmer writing a solver, the structure is the same.
Why the 5x5 puzzle needs a layered algorithm
A sliding puzzle gives you only one legal move type: slide a tile into the adjacent blank. Every method for solving a large puzzle works by fixing tiles you'll never move again, shrinking the problem. If you tried to place tiles in random order, each new tile would knock earlier ones loose.
The layered method prevents that by choosing an order where finishing a stage can be done entirely with moves that confine themselves to the unsolved region.
The 5x5 grid has 25 cells: 24 numbered tiles and one blank. Solved states place tiles 1–24 in reading order with the blank last. The blank's position matters because tile movement depends on it; the layered method intentionally parks the blank in predictable places (usually at the end of the row being built) so that "finish this row without disturbing the row above" becomes a repeatable routine.
One practical consequence: because the puzzle is bigger, the top rows are easy and cheap to fix, but the final block is harder than in the 4×4 case. Most of your technique work concentrates on the last two rows.
What you need before starting: notation and a scrabble tool
Useful shorthand makes the instructions readable. Number the cells by row (R1–R5, top to bottom) and column (C1–C5, left to right). Tile T belongs in position (row, column) matching its number.
For manipulating tiles you need one primitive repeatedly: the 3-cycle, where three tiles rotate among three positions while everything else stays put. On a large board, three cells in an L-shape (two adjacent plus one cell in the next row or column) can be cycled using a short loop that returns the blank to its starting spot.
Learning to rotate a small triangle of tiles is the equivalent of an "algorithm" in the Rubik's-cube sense and underpins every stage.
The other essential is the row-building slide: you position the blank directly below a target tile's destination, work the tile along, and slide it up. Doing this along the top row forces tiles into place without touching solved cells.
Building the top two rows of a 5x5 sliding puzzle
Place tiles 1–10 in order. For each tile, bring it into the row directly beneath its destination and slide it up—with one exception at the row's end.
The first four tiles of row 1 are straightforward: maneuver tile 1 up into C1, then tile 2 into C2, and so on. When you reach the fifth tile of the row (tile 5, or later tile 10), sliding it straight up can push the already-placed neighbor out of position.
Solve this by placing the last two tiles of the row as a pair: bring tile 4 and tile 5 (or 9 and 10) into the two cells below their targets, then rotate them together into the last two cells of the row. The pair trick is the standard way to close out a row without breaking it.
Repeat for row 2. Tiles 6–10 then form the second locked layer. From this point forward, treat rows 1 and 2 as a solid block you'll never move again; all remaining work happens in the bottom three rows.
A useful discipline: after each tile is placed, confirm it before moving on. A single misplaced tile in a "finished" row usually means you neglected the pair trick at the row's end, and it's far cheaper to redo the last two tiles than to discover the error at the end.
Solving the third row and locking it in
Row 3 (tiles 11–15) is where the board starts feeling cramped. The same approach works, but the working space is now only two rows tall (rows 4 and 5), so you have less room to maneuver a tile into position.
For tiles 11–14, use the pair technique across two rows: bring each tile into the lower working rows, then rotate it into its target cell in row 3. Because only two rows remain for shuffling, you'll use more back-and-forth moves, and the 3-cycle becomes the workhorse—rotate the target tile into column position, then lift it into row 3 with a short vertical slide that returns other tiles to their homes.
The last tile of row 3 (tile 15) is the trickiest in this stage. A common technique is to leave tile 15 out of the row and place it using a two-tile rotation with its neighbor: get tile 14 and tile 15 adjacent in the working area, then rotate the pair into the last two cells of row 3. Once tile 15 drops in, rows 1–3 are fixed.
There's a temptation to keep the third row partially open for "flexibility," but that flexibility causes more damage than it helps. Locking row 3 before starting the final block turns the problem into a clean 2×3 puzzle with a well-defined state space.
Finishing the last two rows: rows four and five
At this point you have six cells left: rows 4–5, columns 1–3 (tiles 16–21), plus the blank in the remaining area. The reduction has worked: you're solving a much smaller puzzle whose tiles and blank are confined to a 2×3 region, though the blank can still travel through it freely.
The standard finish uses column-by-column placement. Lock each column's top tile in row 4, then handle row 5 with cycling moves:
- Place row-4 tile 16. Bring tile 16 into row 4, C1 using a vertical lift from the working area; because nothing above it is unsolved, the usual caveats vanish.
- Place row-4 tiles 17 and 18 in the same way.
- Place the row-5 tiles. Tiles 19–21 must fill the bottom row. They may already be where they belong, or they may be permuted. A 3-cycle on three cells of the bottom row rearranges them in one rotation; since all three bottom cells are the same connected region, you can rotate the bottom row until all three tiles line up with their columns.
If the bottom row isn't solved after placing tiles 16–18, the arrangement of tiles 19–21 is a permutation of three tiles in three cells. Every permutation of three items is a product of cycles that can be achieved with repeated 3-cycles, so it always resolves—no special case is needed. The last-column tile is the blank, so you're done when tiles 19, 20, and 21 sit in C1, C2, and C3 of row 5.
This staged finish is not guaranteed to produce a shortest solution, but it is guaranteed to produce a solution whenever the puzzle is solvable.
Is the puzzle solvable? Parity and the swap trap
Not every arrangement of the 24-puzzle can be solved, and the 5×5 has a twist that catches people who test their luck with a misassembled or scrambled toy. The invariant governing sliding puzzles is the parity of the permutation combined with the blank's position; a state is reachable by legal slides only if that combined parity is even.
On an odd-width board like 5×5, the rule simplifies: a position is solvable exactly when the permutation of all tiles has even parity—the number of tile swaps needed to reorder the tiles into 1–24 must be even. (On even-width boards the blank's row position shifts the criterion, which is why the 15-puzzle behaves differently.)
A frequent real-world failure is a physical puzzle that "popped apart" and was reassembled with two tiles swapped. A single swap is an odd permutation, so that state can never be solved by sliding, no matter how clever your algorithm.
Before spending hours on a board, check it: if exactly two tiles are out of place relative to a solved configuration and the rest are correct, the board is unreachable and must be repaired by swapping those two tiles back.
For solving purposes this means a well-designed reduced algorithm need not detect unsolvability—your shuffle or the manufacturer's arrangement is almost always reachable. But if you write a solver, add the parity check first so it doesn't search forever on impossible inputs.
How a computer solves the 5x5 puzzle: search and pattern databases
When "algorithm" means code rather than a human procedure, the layered method is replaced by informed search. The 24-puzzle has an enormous state space—roughly 25!/2 states, around 7.75 × 10^24—so brute-force breadth-first search from a scrambled board is hopeless. The practical algorithms are:
IDA* (iterative-deepening A*) with a strong heuristic. It explores a tree, incrementing a cost bound each iteration, and finds optimal solutions while using only linear memory. For the 24-puzzle it is standard, but the search is dominated by the heuristic's strength.
Pattern databases are the key ingredient. You can precompute exact distances for a subset of tiles: for example, all positions of a group of eight specific tiles, ignoring where the rest are. The distance for that pattern is an admissible lower bound on the full solution length, and the maximum over several disjoint pattern groups gives a much tighter bound than Manhattan distance.
Disjoint additive pattern databases combine group distances for a very strong heuristic; this is what makes optimal 24-puzzle solvers feasible.
Manhattan distance plus linear conflicts is the fast, simple heuristic. It sums each tile's distance to its goal row and column and adds a penalty when two tiles on the same line block each other. It's excellent for the 15-puzzle but weak for 5×5 boards, which is exactly why pattern databases take over at this size.
Iterative approaches such as IDA* with teleporting and pruning are academic refinements; they document that the 24-puzzle is genuinely hard and that the pattern-database method is the practical choice.
5x5 versus 4x4 and 3x3: what actually changes
| Feature | 3×3 (8-puzzle) | 4×4 (15-puzzle) | 5×5 (24-puzzle) |
|---|---|---|---|
| Tiles and blank | 8 + 1 | 15 + 1 | 24 + 1 |
| Reachable states | 181,440 | ~1.05 × 10^13 | ~7.75 × 10^24 |
| Solvability rule | Parity of tile permutation | Parity plus blank-row offset (even width) | Even parity of tile permutation (odd width) |
| Human method | Direct corner-by-corner | Layer method, last layer | Layered reduction, 2×3 finish |
| Practical optimal-solver heuristic | BFS or full table | Manhattan + linear conflict, small pattern DBs | Disjoint pattern databases |
| Hardest stage for humans | Last layer | Final 2×2/2×3 block | Final 2×3 block and third row close-out |
The even-width boards (4×4 and 6×6) share the blank-row parity rule; the 5×5, like all odd-width boards, uses the simpler tile-permutation rule. If you're mentally transferring methods from a 15-puzzle tutorial, this parity difference is the one place to be careful.
Worked reasoning: counting a smaller case
To see why solvability is about parity and not luck, consider the counting. The starting arrangement can be described by listing tiles in reading order and counting how many pairs are "out of order"—the inversion count. Each legal slide changes the inversion count by an even amount on a 5×5 board, so the parity is invariant.
Solved boards have zero inversions (even), so any reachable scramble must also have an even count. A vague scramble with an odd count is unsolvable.
The state counts in the table follow the standard formulas: the 3×3 has 9!/2 reachable states, the 4×4 has 16!/2, and the 5×5 has 25!/2. These figures are combinatorial facts about sliding puzzles, not measured performance, and they explain why search cost explodes with board size.
Building your own 5x5 algorithm: a practical checklist
If the goal is to write a solver rather than run one, the following order of decisions matters more than any single trick:
- Represent the state as a 25-entry array with the blank marked; generate legal moves by swapping the blank with an adjacent tile.
- Implement the solvability test first: compute the tile permutation parity and reject unreachable inputs.
- Start with IDA* plus Manhattan distance and linear conflict to validate the search; it will be slow on hard 5×5 inputs but correct.
- Add pattern databases next: precompute exact distances for a chosen tile group using a forward BFS over the blank and that group, store them in a hash table or array, and use the maximum over groups as a heuristic.
- Choose disjoint groups so distances add rather than overlap, which makes the heuristic dramatically stronger.
- Cap solution reports with the heuristic function's admissible proof in mind: if the heuristic underestimates, IDA* will still find the shortest solution but take longer; if it overestimates, the claimed optimality breaks.
For a human solving the physical puzzle, the "algorithm" reduces to one habit: build rows, close each with the pair trick, lock the third row, then resolve the final 2×3 with vertical lifts and a bottom-row 3-cycle. Practice the 3-cycle until it's automatic; everything else is bookkeeping.
Frequently Asked Questions
Can a 5x5 sliding puzzle always be solved if it's a fair scramble?
Yes, provided it's reachable. A fair scramble comes from legal slides, so it's solvable by construction. Only puzzles that were disassembled and reassembled can fall into an unreachable parity class, and the check is to see whether exactly two tiles are swapped relative to a solved board—an odd permutation that needs repair.
Are there standard algorithms or memorized sequences for each step?
Sliding puzzles have far fewer memorized "algorithms" than twisty puzzles because every move is a simple slide. The reusable primitives are the 3-cycle and the pair-rotation used to close a row. If you want a richer set, treat the final 2×3 as its own mini-puzzle and learn its small move set rather than memorizing long sequences.
Is the 5x5 puzzle harder than the 3x3?
It takes longer and the final block requires more care, but the move logic is simpler per move. The real jump is in computational difficulty: the state space grows to roughly 7.75 × 10^24 reachable states, which is why optimal computer solutions need pattern databases rather than plain searches.
What's the biggest mistake beginners make?
Breaking an already-solved row while working on the next one. The pair trick at the end of each row and leaving the blank in predictable positions near the solved edge prevent this. A second common mistake is treating a parity-impossible board as merely hard; if a physical puzzle won't finish, check for a two-tile swap.
Can I solve the last two rows using only 3-cycles?
The final 2×3 block is always reachable with combination of vertical lifts and 3-cycles, because every permutation of three bottom tiles decomposes into 3-cycles. In practice you place the row-4 tiles first, then rotate the bottom row into order. If the bottom row looks "stuck," confirm the three bottom tiles form the only remaining permutation and cycle them.