How a Sudoku Solver Reasons, Step by Step

After reading this you will know the exact ladder of human techniques a good sudoku solver climbs, how each one narrows the candidates, and how the hardest technique used decides the difficulty grade.

What the solver actually does

A sudoku has 81 cells in a 9 by 9 grid. Each row, each column, and each of the nine 3 by 3 boxes must contain the digits 1 through 9 exactly once. A solver treats every empty cell as a set of candidate digits and then removes candidates using rules that never guess. When a cell has one candidate left, that digit is placed. Placing it removes it from every cell that shares a row, column, or box.

The tool works the same way you would with pencil marks, except it names the technique behind every placement and highlights the row, column, or box that made the deduction valid. Consider a cell in row 4 whose candidates are {5} after its peers are accounted for. That is a naked single: nothing else can go there. Contrast that with a box in which the digit 7 can legally sit in only one of nine cells, even though that cell still shows several candidates. That is a hidden single. Both place one digit, but they see the grid from opposite directions.

When to use it, and when not

Reach for the solver when you are stuck and want to learn the move you missed, when you are checking a puzzle you built, or when you want a difficulty rating before printing a worksheet. Stepping through one deduction at a time turns a dead end into a lesson: you see which unit forced the digit.

Do not use it as a first resort on a puzzle you want to enjoy. Once you have watched the solver find an X-wing, the puzzle is spoiled for you. Use Step to reveal a single move, then go back to solving by hand.

If you are grading a batch of puzzles for a class, run each one and record the difficulty verdict. The verdict names the single hardest technique the solver needed, so a stack of "naked single, hidden single only" puzzles is safe for beginners.

The technique ladder and why order matters

The solver tries techniques from cheapest to most expensive, and stops at the first one that produces a placement or a candidate elimination. The order is not arbitrary. Each rung eliminates the most candidates for the least reasoning, which is exactly how experienced solvers work.

Naked single
A cell has exactly one candidate left. Place it.
Hidden single
A digit fits only one cell within a row, column, or box, even if that cell shows several candidates.
Locked candidates
All copies of a digit inside a box lie in one row or column (pointing), or all copies within a row or column lie in one box (claiming). You then erase that digit from the rest of the line or box.
Naked pair or triple
Two cells in a unit share exactly the same two candidates (a pair), so those two digits are erased from every other cell in the unit. Three cells covering three candidates behave the same way.
Hidden pair or triple
Two digits can go in only two cells of a unit, so every other candidate in those two cells is erased.
X-wing, swordfish
Rectangle and 3 by 3 patterns across rows and columns that pin a digit and eliminate it elsewhere.
XY-wing
A three-cell chain of bi-value cells that forces an elimination at the cell seeing both ends.

Backtracking (trial and error) sits below all of these and is used only when the logical ladder stalls. Every such step is labeled, so you can tell a proven deduction from a tested assumption.

The counting behind the candidate grid

The reason logic can replace guessing is that constraints shrink the search fast. Start from an empty cell with all nine candidates. Each filled peer in its row, column, or box can remove at most one candidate.

c = 9 - |\{d : d \text{ appears among the 20 peers}\}|

Here c is the number of candidates left in a cell, 9 is the full digit set, and the subtracted term counts the distinct digits already placed among that cell's 20 peers (8 in its row, 8 in its column, plus 4 more in its box). A cell has 20 peers, not 24, because the box overlaps the row and column. When those 20 peers cover 8 distinct digits, c = 1 and you have a naked single.

The raw count of complete sudoku grids is 6,670,903,752,021,072,936,960, roughly 6.671 \times 10^{21}. Logic never enumerates them. It prunes the candidate sets until one grid remains.

A worked example from the demo puzzle

Opening moves on the default grid

The demo button loads a standard puzzle written as an 81-character string, reading left to right and top to bottom, with dots for blanks:

53..7....6..195....98....6.8...6...34..8.3..17...2...6.6....28....419..5....8..79

  1. Cell R1C3 sits in a box that already holds 5, 3, 9, 8. Its row holds 5, 3, 7 and its column holds 9, 8. Removing all of these leaves candidates {1, 2, 4, 6}. No single yet.
  2. Look at the top-left box for the digit 4. It can legally sit only in R2C1, because 4 is blocked from the other empty box cells by peers in their rows and columns. That is a hidden single: place 4 at R2C1.
  3. Placing 4 removes it from R2C4 and R2C5. R2C5 now reads {} against 1, 9, 5 in the box and 7, 6 in its column, collapsing to a single candidate. Place it as a naked single.
  4. In the middle-left box, all remaining copies of digit 6 fall in column 1. That is locked candidates (pointing): erase 6 from the rest of column 1 outside the box.
  5. The solver keeps climbing only as far as it must. This grid resolves with singles and one locked-candidates step, so its verdict is Easy.
Singles do almost all the work; one locked-candidates step is the hardest rung reached, so the puzzle grades as Easy.

Reading the difficulty verdict

The verdict is the label of the hardest technique the solver actually needed, matching how human raters grade. A puzzle solved with only naked and hidden singles is Easy. Add locked candidates or a naked pair and it becomes Medium. If a swordfish or an XY-wing was required, it is Hard. If the logic stalled and backtracking was needed, the puzzle is flagged as beyond standard human techniques.

Hardest technique reached and the grade it produces
Hardest techniqueGradeTypical share of published puzzles
Naked or hidden singleEasy~40%
Locked candidates, naked or hidden pairMedium~35%
Triple, X-wing, XY-wingHard~20%
Swordfish or backtrackingExpert~5%

The share column is a rough guide for a mixed newspaper collection, not a guarantee. Your own batch may skew easier or harder.

A cell starts with 9 candidates. Each distinct digit among its 20 peers removes one. When 8 distinct digits appear among the peers, only one candidate remains and the cell is a naked single.

Common mistakes when solving by hand

The errors below cause most stalls that send people to a solver.

  • Miscounting peers. A cell sees 20 peers, not 24. Counting the box corners twice inflates your eliminations and hides real candidates.
  • Confusing naked and hidden singles. A hidden single can hide behind three or four candidates in its cell. If you only scan for cells with one mark, you will miss it.
  • Applying a naked pair across the wrong unit. The two cells must share the same unit (row, column, or box). Two cells with candidates {3,7} in different boxes and different lines eliminate nothing.
  • Guessing too early. If you branch before exhausting singles and locked candidates, you turn a logic puzzle into a search and lose the teaching value.

If the tool reports a contradiction, your input has a typo: two identical digits in one unit, or an over-constrained cell. If it warns of multiple solutions, the puzzle is under-clued and is not a valid sudoku, though one valid grid is still shown.

Related solvers on this site

Sudoku is one of a family of constraint puzzles that yield to the same style of step-by-step reasoning. If you enjoy watching each deduction named, try the Nonogram Solver, which resolves a picture line by line, or the Kakuro Solver, which spells out the sum-combination logic that fixes each cell.

Frequently asked questions

Can I paste a puzzle as a string of numbers?

Yes. Use an 81-character string read left to right, top to bottom, with a dot or a zero for each blank. The demo puzzle above is exactly this format.

Why does the solver ever use trial and error?

A small fraction of valid puzzles cannot be finished with the implemented techniques. When the ladder stalls, the solver tests a candidate and backtracks if it fails. Every such step is labeled so you can see where logic ran out.

Does a harder verdict mean the puzzle is better?

No. Difficulty measures the hardest technique required, not enjoyment. Many solvers prefer a clean Medium puzzle to an Expert one that forces a swordfish.

Is my puzzle sent anywhere?

No. Everything runs in your browser. Your puzzles and the solution log never leave your device.

What if my puzzle has more than one solution?

The tool warns you and still shows one valid grid. A proper sudoku has exactly one solution, so treat the warning as a sign to add clues.