Eight Queens Puzzle
Place n queens on an n × n board so that no two attack each other. Play it by hand, reveal solutions, and see how many exist for each size.
What is the eight queens puzzle?
The eight queens puzzle is an interactive chessboard where you place eight queens so that no two attack each other, and it runs in your browser. A queen attacks along its row, its column and both diagonals, so every queen must sit alone on its own row, column and diagonal. This challenge is also called the eight queens problem. The page also covers the n queens puzzle, which asks for n queens on an n × n board. You can pick any board size from 4 × 4 to 12 × 12. A built-in solver finds every solution for the size you choose, so you can see a finished board whenever you get stuck. Use this page to solve the 8 queens puzzle online, to practise backtracking, or to print a board and work on paper.

How to use the eight queens puzzle
- Choose a board size from 4 × 4 to 12 × 12. Start with 8 × 8 for the classic chess 8 queens puzzle.
- Click a square to place a queen. Click the same square again to remove it.
- Watch for red. Queens that attack at least one other queen turn red, so you can see which ones to move.
- Place all n queens with no conflicts to solve the puzzle.
- If you are stuck, click "Show a solution" to fill the board with a solved position.
- Click "Next solution" to step through the solutions for that size one at a time.
- Click "Clear board" to start over with an empty board.
- Click "Print this board" when you want to solve on paper.
You can also work from the keyboard. Press Tab to move to a square, then press Enter or Space to place or remove a queen. The solver below the board reports the exact number of solutions for your chosen size, and how many of them are different once rotations and reflections are ignored. The list of solutions belongs to the size you chose, so change the size first if you want solutions for another board. Choose any other size to see its exact counts. Reloading the page empties the board again.
What is the 8 queens problem?
The 8 queens problem asks you to place eight queens on an 8 × 8 chessboard so that no two queens share a row, column or diagonal. A queen moves any number of squares along those lines, so two queens on the same line could capture each other.
Each row holds exactly one queen, and each column holds exactly one queen. The diagonals are the tricky part. Two queens also conflict if they sit on the same diagonal, which means the difference between their rows equals the difference between their columns. Solving the puzzle means finding a set of eight squares where every pair avoids all of these lines.
How to solve the N-queens problem
To solve the N-queens problem, place one queen in each row so that it shares no column or diagonal with the queens already placed. The N-queens problem asks for n queens on an n × n board, and a solution exists for every n except 2 and 3.
A few habits make the search easier:
The number of solutions grows quickly with the board size. The 8 × 8 board has 92, and the solver reports the exact count for every size from 4 × 4 to 12 × 12.
- Work row by row, one queen per row.
- Try a small board first. On 6 × 6 there are only four solutions, so it is a good size for a first success.
- Look for families. Rotate or mirror one solution and you get another, so once you have found one pattern, check whether its rotations and reflections are the same answer.
How does the solver work?
The solver below the board is a backtracking search written for this page, and it runs in your browser. For the chosen size it runs a complete search, keeps every solution it finds, and displays one. "Next solution" then steps through the list, so you can compare the boards. For sizes 4 and up the solver finds solutions every time.
Examples
Questions and answers
How many solutions are there for 8 queens on an 8x8 board?
The solver finds 92 solutions on an 8 × 8 board. Of those, 12 are fundamentally different, and the other 80 are rotations or reflections of those 12.
What is the N-queens problem using backtracking?
Backtracking solves the N-queens problem one row at a time. Place a queen in the first safe column of the next row. When a row has no safe square, go back to the previous row and move that queen to its next safe column.
What does a red queen mean?
A red queen attacks at least one other queen on the board. Move it to a square where no other queen can reach it, and the red colour goes away.
Can I print the board?
Yes. Click "Print this board" to print the current board. It prints whatever is on the board, so leave it empty if you want a blank grid to solve on paper.
Why does the board start at 4 × 4?
There is no solution for 2 × 2 or 3 × 3, so those sizes are left out. A 1 × 1 board has a single queen that is trivially safe.
Who created the eight queens puzzle?
The puzzle was published by the chess composer Max Bezzel in 1848. It was later generalised into the N-queens problem.
Does the tool save my board?
No. Nothing is stored or sent anywhere. Reload the page and the board is empty again.
Related chess tools
Updated