Blog

How Sudoku Puzzles Are Generated

Every board you play on this site was built seconds before you saw it — not pulled from a database of ten thousand pre-made puzzles. Here's what actually happens in that fraction of a second: how a valid solution is constructed, how clues are carved away without ever breaking the puzzle, and why we rate difficulty by the techniques a board demands rather than by how many clues it shows.

Step 1: build a finished board first

Generation runs backwards from what you might expect. The generator doesn't place clues and hope a puzzle emerges — it builds a complete, solved 9×9 grid first, and only then decides what to hide.

Filling the grid uses a classic algorithm called backtracking. Working cell by cell, it places a random digit that doesn't conflict with the row, column, or 3×3 box, and moves on. When it reaches a cell where no digit is legal, it doesn't give up — it backs up one cell, changes that earlier choice, and pushes forward again. It's a methodical version of how you'd solve a maze: go until you hit a wall, retreat to the last junction, take the other branch. With randomised digit order at each cell, the process lands on one of the roughly 6.7 × 10²¹ valid Sudoku grids — a different one essentially every time.

Step 2: remove clues — carefully

A solved grid is not a puzzle. The puzzle is what's left after clues are removed, and the removal is where all the care lives. The generator deletes candidate cells one at a time — and after every single removal it hands the board to a solver with one question: does this puzzle still have exactly one solution?

If yes, the clue stays gone and removal continues. If no — if erasing that clue lets two different solutions exist — the clue goes straight back and the generator tries somewhere else. That check after every removal is the whole ballgame. It's the difference between a puzzle and a guessing game.

A complete solved Sudoku grid on the left is turned into a puzzle on the right by removing clues, keeping exactly one solution5346789126721953481983425678597614234268537917139248569615372842874196353452861795376195986863483172662841958791. Full solution2. Clues removed
The generator works backwards: a complete solution is built first (left), then clues are removed one by one (right) — with a uniqueness check after every removal. What remains is a puzzle with exactly one answer.

Incidentally, this is why "number of clues" is a poor measure of difficulty. The fewest clues a valid single-solution Sudoku can have is 17 — a famous mathematical result — but plenty of 17-clue puzzles are easier than a nasty 26-clue one. What matters is not how much is missing, but what kind of reasoning the gaps demand.

Step 3: rate the difficulty by technique, not by count

To grade a board, the generator solves it the way a human would: with a toolbox of named techniques, tried from simplest to hardest. Can the whole board be finished with singles alone — scanning for the only legal cell for a digit? That's an Easy or Medium board. Does it stall until you use naked pairs or hidden pairs? That's Hard. Does it demand pointing pairs, box/line reduction or triples before a single new digit can be placed? Expert, Master or Extreme, depending on how deep the chain goes.

The hardest technique the solver was forced to use becomes the board's rating. So when you pick Hard on Sudoku Zen, you're not getting "Medium with fewer clues" — you're getting a board that provably cannot be finished without Hard-level reasoning.

Generation pipeline: build a full grid by backtracking, remove a clue, check the solution is still unique, restore the clue if not, then rate difficulty by the hardest technique requiredBuild full grid(backtracking)Remove one clueStill exactlyone solution?Rate difficulty by hardesttechnique neededyes, keep goingno: put it back
The full pipeline. The loop on the left runs dozens of times per board: remove a clue, re-solve, and restore the clue if uniqueness ever breaks.

Why the single-solution guarantee matters to you

A puzzle with two solutions is broken in a way you can feel but not always name: you reach a point where the logic simply runs out, and the "solution" comes down to picking one of two mirror arrangements. No technique can help, because no technique exists — the information isn't on the board. Sites that generate boards without a uniqueness check ship puzzles like this constantly, and they're what teach people the false lesson that "hard Sudoku means guessing".

It never does. Because every board here survives the uniqueness check, every board is solvable by pure deduction — and when you're stuck, the honest explanation is a technique you haven't spotted yet. Our strategy guide covers eight of them, with a worked diagram for each.

Play Sudoku Zen — six difficulties, every board guaranteed