Sudoku Solver
Introduction: how Sudoku constraints shape each row, column, and box
Sudoku is a 9×9 logic puzzle built around a very compact rule set: every row, every column, and every 3×3 box must contain the digits 1 through 9 exactly once. The given numbers in a puzzle are not decorative accents; they are the fixed clues that force the remaining blanks into a unique arrangement when the puzzle is well formed. That is why a Sudoku board can look almost empty and still be completely determined by a small collection of starting digits. The challenge is not arithmetic so much as constraint management, because each new placement narrows the legal choices in the same row, the same column, and the same box.
The rules of Sudoku can be described with set notation, which is a natural fit for a puzzle made of discrete cells. Let be a set of ordered triples where and index the row and column, and is the value in that cell. For a valid solution, each number from 1 to 9 must appear once in every row: . Similar constraints apply to columns and boxes. This discrete structure is what makes Sudoku a natural constraint-satisfaction problem: every blank cell is a question about which digits survive the row, column, and box tests at the same time.
If you prefer a compact notation, Sudoku can also be stated one unit at a time. The row set must equal . The column set must also equal . Finally, each 3×3 box set must match . That is the same legality test the backtracking search applies whenever it tries a digit in a blank cell.
The backtracking method used by this Sudoku solver
Backtracking is a practical match for Sudoku because each tentative digit can be checked immediately against the puzzle's rules. The solver walks through the grid, skips cells that already contain a clue, and tries digits 1 through 9 in each blank. If a trial digit violates a row, column, or box, it is discarded at once. If a choice looks valid but later leads to a dead end, the solver rewinds to the previous blank and tries the next candidate. When the last cell is reached, every unit is consistent and the puzzle is solved. That makes the algorithm easy to understand: it is just controlled guessing with instant rule checks.
How long the search takes depends on how constrained the Sudoku puzzle is. A grid with many givens usually collapses quickly because each new digit cuts down neighboring options, while a sparse or tricky puzzle may force deeper trial-and-error. In algorithm terms, the worst case is still exponential, but Sudoku's local restrictions prune large parts of the search tree before they ever become expensive. A simple heuristic such as filling the most constrained cell first can shrink the work dramatically, which is why human solvers and computer solvers often converge on the same idea from different directions.
Sudoku strategies and how this backtracking solver treats them
Human solvers often give names to recurring Sudoku patterns, and the table below shows how those ideas relate to the straightforward solver on this page. The page itself does not try to mimic every advanced pencil-and-paper method, but it benefits from the same underlying logic: every good move is one that removes uncertainty without breaking the row, column, or box rules. That keeps the discussion grounded in the actual puzzle instead of turning Sudoku into an abstract exercise with no visible outcome.
| Technique | Description | Algorithmic analogue |
|---|---|---|
| Single Candidate | A cell has only one legal digit after row, column, and box checks. | Directly handled by the legality check. |
| Hidden Single | A digit can be placed only once inside a row, column, or box. | Useful as a heuristic for choosing the next blank. |
| Naked Pair | Two cells in one unit share the same pair of candidates, which blocks those digits elsewhere. | A stronger pruning rule before guessing. |
| X-Wing | Two rows or columns line up on the same candidate pattern, which can eliminate that digit in intersecting units. | Not used by this page's basic backtracking solver. |
Sudoku formulas: what a valid grid must satisfy
Sudoku also sits inside combinatorics, because a solved board is more than a picture of numbers: it is a structured assignment of digits that satisfies a set of uniqueness rules. A finished puzzle is a Latin square with the extra 3×3 box restriction, which is why it is more constrained than a plain row-and-column arrangement. One celebrated count puts the number of valid completed grids at 6,670,903,752,021,072,936,960, a reminder that the space of legal boards is enormous even though each move feels local. Researchers have also studied symmetry classes by factoring out row swaps, column swaps, reflections, and digit relabeling, which shows how much structure hides behind the simple-looking grid.
A classic Sudoku puzzle can be discussed in terms of the minimum clue count needed for a unique solution. The widely cited lower bound is 17 clues, which means a finished puzzle can leave a large majority of cells blank and still have exactly one completion. Sudoku has also been framed as an exact cover problem, where each candidate digit placement corresponds to a row in a matrix and each constraint becomes a column. Choosing a set of rows that covers every column once yields a valid solution, and that viewpoint helps explain why backtracking and other search methods work so well on a puzzle with such short rules.
The grid is useful for graph theory too. If you treat each cell as a vertex and connect cells that share a row, column, or box, Sudoku becomes a graph-coloring problem with nine colors. Every cell can be adjacent to as many as 20 others once overlaps are counted, which explains why the puzzle is tightly constrained even though the rules are short. These viewpoints help explain why some puzzles feel effortless while others resist simple scanning: the same rule set can produce very different search spaces, and the solver must respect all of them at once.
The solver on this page deliberately stays simple. It relies on local consistency checks and recursion rather than advanced human-style patterns, which keeps the implementation compact and easy to trust in the browser. Because the puzzle is solved on your device, the grid never needs to be uploaded to a server, and the page still works without a network connection. That makes it handy for paper puzzles, app screenshots, or any situation where you want a quick check of a partially filled board. It also means the result depends entirely on the digits you type, so a copied clue that is off by one cell will still send the search down the wrong branch.
If you want to test the solver, paste the sample grid encoded below into the cells row by row. The zeroes mark blanks, so the string can reproduce the starter puzzle exactly: 530070000600195000098000060800060003400803001700020006060000280000419005000080079. Once you press Solve, the backtracking routine works from left to right, top to bottom, filling forced cells first and only guessing when no digit is forced. Watching the board change is a practical way to see how a recursive search progresses through a Sudoku puzzle, because each filled square immediately changes the legal possibilities around it.
For a more formal check, the symbols below summarize what must be true of each completed row, column, and box. The row set, the column set, and the box set must each contain the digits 1 through 9 with no repeats, which is the same rule the solver enforces one cell at a time. Thinking about the puzzle this way turns a finished board into a collection of exact sets rather than a picture of digits. Define rows, columns, and digits. For each row , the set must equal the digits 1 through 9. Similar set equality holds for columns and boxes. This set-based formulation clarifies the problem's structure and aligns with constraint programming techniques where variables take values from domains subject to rules expressed as sets or relations.
Sudoku also makes a useful laboratory for research in human reasoning. Solvers compare counting methods, candidate marking, pattern recognition, and pure trial-and-error, while computer scientists use puzzles to benchmark search algorithms. Some people solve by visual grouping, others by tracking missing digits in each unit, and many switch between the two approaches depending on the grid. That mix of intuition and logic is part of what gives Sudoku its lasting appeal, and it is also the reason a small browser solver can still be surprisingly instructive.
Because this utility runs inside your browser, it is suited to private practice, offline use, and quick experimentation with puzzle inputs. You can inspect the page source, try a different puzzle, or compare how a sparse grid behaves versus a nearly complete one. The compact script makes it easy to understand where each digit comes from and how one wrong clue can block the search. In that sense, the solver is both a helper and a teaching tool, especially when you want to see how far simple rules can go before recursion takes over.
In short, the Sudoku solver turns a classic pencil puzzle into an immediate browser check: enter the givens, press Solve, and let the rules fill the rest. Whether you are verifying a newspaper puzzle or learning how recursion works, the page shows how a small set of constraints can produce a complete and elegant solution. The solved board is not created by magic; it is the consequence of repeatedly asking which digits remain legal in the next blank cell.
How to use this Sudoku solver
- Enter the Sudoku clues exactly as they appear in your puzzle, and leave every blank cell empty.
- Type only digits 1 through 9; each input box accepts a single number because Sudoku cells never need anything else.
- Check that repeated digits do not already appear in the same row, column, or 3×3 box before you solve.
- Press Solve to let the backtracking search complete the grid, then compare the filled board with your original puzzle to catch any entry mistakes.
Worked example: solving a nearly complete Sudoku grid
A good way to see the Sudoku solver in action is to start with a nearly finished board that has only a few blanks. For the sample puzzle above, the zeros in the encoded string mark the empty cells, so the solver has enough structure to make many forced placements before it needs to guess. If the puzzle is valid, each step narrows the remaining choices until only one digit fits a cell. If the grid contains a conflict, the search quickly runs out of legal moves, which is a useful signal that one of the givens was copied incorrectly. This is exactly the sort of test that makes a browser solver handy: it can confirm a puzzle quickly without changing the logic of the puzzle itself.
Limitations and assumptions for Sudoku solving
A Sudoku solver can only work with the clues you enter, so it is only as reliable as the grid copied from the original puzzle. If a row, column, or box already contains the same digit twice, the search may fail or produce a contradiction. Very open puzzles can also take longer than almost complete ones because the solver has more branches to consider. In other words, the result depends on accurate givens, consistent Sudoku rules, and a puzzle that really does have a valid completion.
This browser tool does not judge whether a puzzle was published correctly or whether a clue should be there; it simply follows the Sudoku constraints encoded in the page. It also cannot repair a broken puzzle for you, so it is worth double-checking the original grid before treating a failed solve as final. If two entries look equally plausible, the solver will still explore them in order, which means a typo in one square can send the search down the wrong branch. The most useful check is often to compare the completed grid against the puzzle you started with and see which cell first became inconsistent.
Arcade Mini-Game: Sudoku Candidate Chase
Use this quick arcade run to practice spotting useful Sudoku clues, conflicts, and dead-end guesses before you rely on a finished grid.
Start the game, then use your pointer or arrow keys to catch useful Sudoku clues and avoid illegal placements.
