# Eight queens puzzle

The eight queens puzzle is the problem of placing eight chess queens on a standard 8×8 chessboard so that no two queens attack each other, meaning that no two share a row, a column, or a diagonal.<sup>[1](https://raboof.github.io/ewd/EWD316.9.html)</sup> It has 92 distinct solutions, or 12 fundamental solutions when arrangements related by rotation or reflection of the board are counted as one.<sup>[2](https://users.encs.concordia.ca/~chvatal/8queens.html)</sup> First published as a chess problem in 1848, it became one of the standard examples of constraint satisfaction and backtracking in computer science.<sup>[3](https://www.cs.utexas.edu/~mitra/csSpring2023/cs313/assgn/assgn13.html)</sup>

| Key fact | Detail |
|---|---|
| Statement | Place 8 queens on an 8×8 board so that no two share a row, column, or diagonal<sup>[1](https://raboof.github.io/ewd/EWD316.9.html)</sup> |
| Solution count | 92 distinct solutions; 12 fundamental solutions up to rotation and reflection<sup>[2](https://users.encs.concordia.ca/~chvatal/8queens.html)</sup> |
| Symmetry arithmetic | 11 fundamental solutions have 8 variants each and 1 has 4, giving 11×8 + 1×4 = 92<sup>[4](https://queens.game/blog/eight-queens-puzzle-92-solutions-12-unique)</sup> |
| Origin | Proposed by Max Bezzel in the *Berliner Schachzeitung*, 1848; all 92 solutions published by Franz Nauck in 1850<sup>[2](https://users.encs.concordia.ca/~chvatal/8queens.html)</sup> |
| Generalization | The n-queens problem asks the same question for n queens on an n×n board; solutions exist for every n ≥ 4<sup>[5](https://arxiv.org/abs/2105.11431)</sup> |
| Growth rate | The number of n-queens configurations is ((1 ± o(1))·n·e^(−α))^n with α = 1.942 ± 3×10^−3<sup>[6](https://arxiv.org/abs/2107.13460)</sup> |
| Largest exact count | N = 27, with 234,907,967,154,122,528 solutions enumerated<sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC2682695/)</sup><sup> • </sup><sup>[21](https://math.uni.lu/eml/assets/reports/2022/queens.pdf)</sup> |

## Problem and constraints

A queen attacks along its row, its column, and both diagonals, so a valid placement must satisfy three families of constraints at once. Because two queens in the same row attack each other, a solution places exactly one queen in every row, and the same argument applies to columns; a placement is therefore equivalent to a permutation of the columns, with the additional requirement that no diagonal holds more than one queen.<sup>[6](https://arxiv.org/abs/2107.13460)</sup> In Dijkstra's formulation, the configurations sought are those in which no two queens may be on the same row, the same column, or the same diagonal.<sup>[1](https://raboof.github.io/ewd/EWD316.9.html)</sup>

The problem can be written formally as a constraint satisfaction problem with a Boolean variable X<sub>ij</sub> for each square, constrained so that at most one queen occupies any row, any column, or either family of diagonals, and exactly N squares are occupied.<sup>[8](https://inst.eecs.berkeley.edu/~cs188/textbook/csp/csps.html)</sup> Constraint satisfaction problems of this kind are NP-hard in general, which motivates the puzzle's long use as a test case for search algorithms.<sup>[8](https://inst.eecs.berkeley.edu/~cs188/textbook/csp/csps.html)</sup>

## History

**Origin.** The puzzle was apparently first proposed by Max Bezzel, a German chess player and problem composer, in the *Berliner Schachzeitung* in 1848.<sup>[2](https://users.encs.concordia.ca/~chvatal/8queens.html)</sup> It soon attracted the attention of several eminent mathematicians, including [Carl Friedrich Gauss](https://www.edgepedia.org/carl-friedrich-gauss).<sup>[5](https://arxiv.org/abs/2105.11431)</sup>

**First solutions.** Franz Nauck published the solutions in the *Leipziger Illustrirte Zeitung* in 1850, presenting all 92 arrangements for the 8×8 board and also raising the generalized n-queens problem.<sup>[2](https://users.encs.concordia.ca/~chvatal/8queens.html)</sup><sup> • </sup><sup>[3](https://www.cs.utexas.edu/~mitra/csSpring2023/cs313/assgn/assgn13.html)</sup> In 1874, S. Gunther suggested finding solutions by means of determinants, and the English mathematician J. W. L. Glaisher extended this method, publishing a determinant-based treatment in the *Philosophical Magazine* in December 1874.<sup>[3](https://www.cs.utexas.edu/~mitra/csSpring2023/cs313/assgn/assgn13.html)</sup><sup> • </sup><sup>[9](https://bobson.ludost.net/copycrime/mgardner/gardner04.pdf)</sup> Pauls showed in 1874 that solutions exist for every board size n ≥ 4, settling the existence question for the generalized problem.<sup>[5](https://arxiv.org/abs/2105.11431)</sup>

**Entry into computing.** In 1971 and 1972, [Edsger W. Dijkstra](https://www.edgepedia.org/edsger-w-dijkstra), the Dutch computer scientist known for his work on structured programming, used the eight queens problem as a worked example of depth-first backtracking, first in his notes on structured programming and then in Chapter 9 of *A Short Introduction to the Art of Programming* (EWD 316).<sup>[1](https://raboof.github.io/ewd/EWD316.9.html)</sup><sup> • </sup><sup>[10](https://www.cs.utexas.edu/~EWD/transcriptions/EWD03xx/EWD316.9.html)</sup><sup> • </sup><sup>[3](https://www.cs.utexas.edu/~mitra/csSpring2023/cs313/assgn/assgn13.html)</sup> A 1974 SIAM Journal on [Computing](https://www.edgepedia.org/computing) paper by Jay P. Fillmore and S. G. Williamson described backtracking in terms of chains of partitions and used the eight queens problem as a named example, connecting it to isomorph rejection under a group of symmetries.<sup>[11](https://epubs.siam.org/doi/10.1137/0203004)</sup>

## Counting the 92 solutions

The 92 distinct solutions fall into 12 equivalence classes under the board's eight symmetries, the four rotations and four reflections.<sup>[2](https://users.encs.concordia.ca/~chvatal/8queens.html)</sup> A fundamental solution usually has eight variants, obtained by rotating by 90, 180, or 270 degrees and reflecting each rotational variant.<sup>[4](https://queens.game/blog/eight-queens-puzzle-92-solutions-12-unique)</sup> One of the twelve, Solution 12 in Chvátal's listing, is invariant under a 180-degree rotation, so its equivalence class contains only four solutions; none of the twelve is equal to its own 90-degree rotation.<sup>[2](https://users.encs.concordia.ca/~chvatal/8queens.html)</sup><sup> • </sup><sup>[4](https://queens.game/blog/eight-queens-puzzle-92-solutions-12-unique)</sup> The total is therefore 11×8 + 1×4 = 92, which is why the count does not divide evenly by 8.<sup>[4](https://queens.game/blog/eight-queens-puzzle-92-solutions-12-unique)</sup>

No solution can be equivalent to its own reflection, because that would require two queens facing each other; for n > 1 this rules out that symmetry in general.<sup>[4](https://queens.game/blog/eight-queens-puzzle-92-solutions-12-unique)</sup> A complete brute-force check confirms that the 92 arrangements are the only ones.<sup>[2](https://users.encs.concordia.ca/~chvatal/8queens.html)</sup>

## The n-queens generalization

The natural generalization asks for the number Q(n) of ways to place n mutually non-attacking queens on an n×n board. The sequence begins 1, 1, 0, 0, 2, 10, 4, 40, 92, 352, 724, 2680, 14200 for n = 1 through 13, recorded as OEIS A000170; the zero entries at n = 2 and n = 3 reflect boards too small to admit any solution.<sup>[12](https://oeis.org/A000170)</sup> Exact enumeration grows exponentially: the largest system fully counted is N = 27, with 234,907,967,154,122,528, or about 2.35×10^17, solutions.<sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC2682695/)</sup><sup> • </sup><sup>[21](https://math.uni.lu/eml/assets/reports/2022/queens.pdf)</sup>

**Asymptotics.** In 2021, Michael Simkin, a mathematician then working on combinatorics at Harvard and later at the [Hebrew University of Jerusalem](https://www.edgepedia.org/hebrew-university-of-jerusalem), proved that there is a constant α = 1.942 ± 3×10^−3 such that Q(n) = ((1 ± o(1))·n·e^(−α))^n, roughly (0.143·n)^n configurations.<sup>[6](https://arxiv.org/abs/2107.13460)</sup><sup> • </sup><sup>[12](https://oeis.org/A000170)</sup> The constant is characterized as the solution to a convex optimization problem over probability measures on the square, and the proof introduces limit objects for configurations, called queenons, together with an entropy function that counts configurations approximating a given queenon.<sup>[6](https://arxiv.org/abs/2107.13460)</sup> Earlier, Luria and Simkin had established the lower bound ((1 − o(1))·n·e^(−3))^n using a random greedy construction of toroidal configurations, in which diagonals wrap around the board, followed by an absorber stage, proving a conjecture of Rivin, Vardi, and Zimmerman in strong form.<sup>[5](https://arxiv.org/abs/2105.11431)</sup>

**Counting methods.** Because complete enumeration becomes infeasible, [Monte Carlo](https://www.edgepedia.org/monte-carlo) methods estimate Q(n) by comparing the original problem with a generalized problem that has fewer constraints, sampling binary matrices that identify queen positions with Swendsen-Wang style algorithms.<sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC2682695/)</sup><sup> • </sup><sup>[13](https://arxiv.org/abs/2407.08830)</sup> A statistical-mechanics line of work maps the problem to a lattice gas with repulsive interactions along shared rows, columns, and diagonals, whose ground states are exactly the Q(N) solutions.<sup>[14](https://arxiv.org/abs/2605.10326)</sup>

## Algorithms

**Backtracking.** The classical solution places queens row by row, abandoning a branch as soon as a partial placement has a conflict. Dijkstra's exposition frames this as generating a larger set B of configurations that contains the solution set A, then filtering B by a cheap membership test, choosing B as small as possible so that few candidates need rejection.<sup>[1](https://raboof.github.io/ewd/EWD316.9.html)</sup> Practical implementations track occupied columns and diagonals with three sets indexed by row+col and row−col, making each attack check constant time, and bitmask versions pack the three sets into integers shifted per row.<sup>[15](https://prism.nicofortuin.com/algorithms/n-queens/)</sup>

**Local search.** The min-conflicts heuristic of Steven Minton, Mark D. Johnston, Andrew B. Philips, and Philip Laird starts from an inconsistent assignment and repeatedly moves a queen to the square minimizing constraint violations; on the n-queens problem this repair method was shown empirically to perform orders of magnitude better than traditional backtracking.<sup>[16](https://jmvidal.cse.sc.edu/lib/minton92a.html)</sup> Metaheuristics including genetic algorithms and simulated annealing have also been applied to find the 92 solutions.<sup>[17](https://ieeexplore.ieee.org/abstract/document/7041114)</sup>

**Role as a benchmark.** The n-queens problem serves as a standard benchmark for constraint satisfaction, appearing in solver benchmark suites and in comparisons of uninformed search, backtracking, hill climbing, and A*.<sup>[18](https://www.cs.cmu.edu/afs/cs.cmu.edu/project/learn-43/lib/photoz/.g/web/.g/group/group2/g/sat/sat-survey.pdf)</sup><sup> • </sup><sup>[19](https://conferences.vntu.edu.ua/index.php/mn/mn2026/paper/view/26765)</sup> Extensions studied in the research literature include higher-dimensional boards, formulated with integer programming, and the toroidal variant in which diagonals wrap around.<sup>[20](https://arxiv.org/abs/2406.06260)</sup><sup> • </sup><sup>[5](https://arxiv.org/abs/2105.11431)</sup>

## References

1. [Edsger W. Dijkstra, A Short Introduction to the Art of Programming (EWD 316), Chapter 9](https://raboof.github.io/ewd/EWD316.9.html)
2. [Vašek Chvátal, All solutions to the problem of eight queens](https://users.encs.concordia.ca/~chvatal/8queens.html)
3. [Eight Queens Problem, programming assignment notes, UT Austin](https://www.cs.utexas.edu/~mitra/csSpring2023/cs313/assgn/assgn13.html)
4. [Eight Queens Puzzle: 92 Solutions, Only 12 Unique, Queens.Game](https://queens.game/blog/eight-queens-puzzle-92-solutions-12-unique)
5. [Zur Luria, Michael Simkin, A lower bound for the n-queens problem, arXiv:2105.11431](https://arxiv.org/abs/2105.11431)
6. [Michael Simkin, The number of n-queens configurations, arXiv:2107.13460](https://arxiv.org/abs/2107.13460)
7. [Counting solutions for the N-queens and Latin-square problems by Monte Carlo simulations, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC2682695/)
8. [Constraint Satisfaction Problems, CS 188 textbook, UC Berkeley](https://inst.eecs.berkeley.edu/~cs188/textbook/csp/csps.html)
9. [Martin Gardner, The Unexpected Hanging and Other Mathematical Diversions (PDF)](https://bobson.ludost.net/copycrime/mgardner/gardner04.pdf)
10. [E.W. Dijkstra Archive, EWD 316 Chapter 9 transcription, UT Austin](https://www.cs.utexas.edu/~EWD/transcriptions/EWD03xx/EWD316.9.html)
11. [Jay P. Fillmore, S. G. Williamson, On Backtracking: A Combinatorial Description of the Algorithm, SIAM J. Comput. 3(1), 1974](https://epubs.siam.org/doi/10.1137/0203004)
12. [OEIS A000170, Number of solutions to the n-queens problem](https://oeis.org/A000170)
13. [Counting N Queens, arXiv:2407.08830](https://arxiv.org/abs/2407.08830)
14. [Statistical mechanics of the N-queens problem, arXiv:2605.10326](https://arxiv.org/abs/2605.10326)
15. [N-Queens, visualized and explained, Prism](https://prism.nicofortuin.com/algorithms/n-queens/)
16. [Steven Minton et al., Minimizing conflicts: a heuristic repair method, Artificial Intelligence 58 (1992)](https://jmvidal.cse.sc.edu/lib/minton92a.html)
17. [Solving 8-Queens Problem by Using Genetic Algorithms, Simulated Annealing, and Randomization Method, IEEE](https://ieeexplore.ieee.org/abstract/document/7041114)
18. [SAT survey, Carnegie Mellon University](https://www.cs.cmu.edu/afs/cs.cmu.edu/project/learn-43/lib/photoz/.g/web/.g/group/group2/g/sat/sat-survey.pdf)
19. [Experimental Comparison of Uninformed and Heuristic AI Algorithms for N Puzzle and 8 Queen Puzzle, VNTU conference](https://conferences.vntu.edu.ua/index.php/mn/mn2026/paper/view/26765)
20. [Tim Kunt, The n-Queens Problem in Higher Dimensions, arXiv:2406.06260](https://arxiv.org/abs/2406.06260)
21. [math.uni.lu](https://math.uni.lu/eml/assets/reports/2022/queens.pdf)

---
*Topic: Encyclopedia › Physical world and mathematics › Mathematics and statistics › Logic and discrete mathematics › General discrete mathematics and discrete structures › Combinatorics › Enumerative combinatorics › Enumerative combinatorics overview and specific enumeration problems*

*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

*Copyright 2026 EdgeChat AI, a subsidiary of Biostate AI.*

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license
