How sudokus are generated: the technology behind every board

By Miguel Arechaga

Every time you press "new sudoku," a different, balanced board appears with a unique solution. It can seem like magic, but behind it lies a very elegant logical process that anyone can understand without knowing how to code. In this article I'll walk you through, step by step and in plain language, how a computer builds a sudoku from scratch and makes sure it's fair and solvable.

Step 1: build a complete, valid grid

Contrary to what many people imagine, a generator doesn't start by placing loose clues. It starts the other way around: by filling an entire nine-by-nine board, all 81 numbers in place, respecting every rule. To do this it goes cell by cell, trying random numbers and checking that they don't break any row, column, or block constraint. If at some point it runs out of valid options, it backs up and tries a different combination. This "try and backtrack" technique is called backtracking, and it guarantees a perfectly legal, complete grid at the end. That grid will become the solution to the future sudoku.

Step 2: remove numbers without losing the unique solution

With the board full, the generator starts erasing numbers one by one, in random order. But it doesn't erase randomly: every time it removes a digit, it checks one sacred condition. The sudoku that remains must still have exactly one possible solution. If erasing a number makes the board admit two or more ways to complete it, that digit goes back in place and another one is tried instead. This check is what separates a real sudoku from a mere pile of cells: a good sudoku never forces you to guess, because there's only one logical path to the finish.

The heart of the system: counting solutions

Everything, therefore, depends on being able to quickly answer one question: "does this board have a single solution or more than one?" To do that, the generator uses a small internal solver that attempts to solve the puzzle and counts how many distinct solutions it finds. As soon as it detects a second one, it stops, because it already knows that gap can't be left empty. Doing this efficiently is the key to making generation instant, and it's achieved with tricks like always choosing the cell with the fewest possibilities to speed through the analysis.

How difficulty is calibrated

Here's an idea that surprises a lot of people: a sudoku's difficulty doesn't depend only on how many numbers are left visible. It does matter, yes (a board with more gaps tends to be harder), but what really sets the level is what kind of reasoning is needed to solve it. An easy sudoku can be completed with basic scanning; an expert one may require techniques like hidden pairs or X-Wing. That's why generators don't just count clues: they aim for an approximate number of visible cells per level and rely on the fact that, with that many gaps, the situations typical of each difficulty will show up. It's a balance between how many numbers to leave and what logical challenges to trigger.

Why they never repeat

Since every game starts from a different, randomly generated complete grid, the possible combinations are astronomical: there are billions upon billions of essentially different sudokus. In practice this means that even if you played thousands of games, you'd never get the exact same board twice. It's the big advantage of computer generation over printed books: a literally endless source of puzzles, each one new and verified.

How MundoSudoku's boards work

Everything you just read is exactly what happens under the hood of MundoSudoku every time you start a game: a complete grid is built, cells are emptied while checking at each step that the solution stays unique, and the number of clues is adjusted to the level you chose. That's why you can play knowing that any board, however hard, can always be solved with pure logic and no guessing. And if you're curious about the history behind all this, take a look at the history of sudoku, where we cover how it went from paper to automatic generators.

Shall we try a freshly generated board?
Every game is unique and always solvable through logic.
🎮 Play now for free 📅 Daily sudoku
Miguel Arechaga, creator of MundoSudoku

Written by Miguel Arechaga

Creator and developer of MundoSudoku. Passionate about logic puzzles, he shares guides and tips to help you enjoy and improve at sudoku.