N-Queens Puzzle Generator
Place eight queens on a chessboard so that no two attack each other. It is the standard example for backtracking, and the numbers behind it are more surprising than the puzzle: there are 92 solutions on an 8x8 board, only 4 on a 6x6, and none at all on 2x2 or 3x3. This generates one solution at random and, at the sizes where it is affordable, counts every solution there is.
What this generator does
Places one queen per row by backtracking, trying columns in a random order so different runs produce different solutions, then re-checks the finished placement for shared columns and shared diagonals. At ten queens or fewer it also enumerates every solution to report the exact total.
How to use this tool
- Choose a board size and generate a placement.
- Check it yourself: no two queens share a row, column or diagonal.
- Read the total number of solutions and compare across sizes.
- Try 6x6, which has fewer solutions than 5x5 despite the larger board.
Understanding the controls
- Board size
- Between 4 and 10. There is no solution at all on a 2x2 or 3x3 board, and above ten the exhaustive count becomes slow.
- Seed
- Any word reproduces exactly the same placement, so the same puzzle can be set and marked later.
Common use cases
- Teaching backtracking with a problem that has a countable answer
- Chess puzzles and classroom starters with a verified solution
- Demonstrating that solution counts do not grow smoothly with board size
- Test instances for a constraint-solving implementation
- Setting the same placement twice from a seed
How this generator works
Only one queen can sit in each row, so the search works row by row and only ever chooses a column — which reduces the problem from placing pieces on 64 squares to choosing 8 numbers. A column is rejected if any earlier queen shares it, or if the difference in columns equals the difference in rows, which is exactly what sharing a diagonal means. The counting pass uses the same rule without the randomisation.
Randomness and fairness
The column order is randomised so each run finds a different solution; the placement is then verified. A seed reproduces the same solution exactly and is therefore explicitly not cryptographically secure. Without a seed the browser's cryptographically secure generator is used.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- Boards from 4x4 to 10x10; the exhaustive solution count is what limits the upper end.
- Solutions related by rotation or reflection are counted separately, which is the standard convention.
- One solution is shown at a time rather than all of them.
- No difficulty rating — every size is equally easy for the solver, however hard it is by hand.
- Placements are not stored between visits; seed one you want again.
Privacy and your data
The placement and the solution count are computed in your browser. Nothing about the board or your seed is transmitted or kept.
Related generators
- Knight's Tour GeneratorA knight's route visiting every square of the board exactly once, with every step re-checked as a legal knight move.
- Random Chess Position GeneratorPositions played out from the opening by legal moves, given in FEN with the game that reaches them — so you can replay it and see for yourself.
- Star Battle Puzzle GeneratorStar Battle grids with one star per row, column and region, no two touching — with the region shapes proved to admit only one arrangement.
- Sudoku GeneratorPrint a sudoku with exactly one solution — 4x4, 6x6 or full 9x9, four difficulties, with the answer key and a seed to reprint it.