Chess puzzle · Graph theory
The knight's tour
Put a chess knight on any square and move it so that it lands on every square of the board exactly once. The puzzle is more than a thousand years old, and a rule of thumb from 1823 still solves it faster than most people can. Play it first, then see how it works.
Visiting every point exactly once is the Starwalk mode in Between Stars, a calm puzzle game for iPhone. Free on the App Store.
Play the knight's tour
Tap a square to place the knight. Squares it can jump to next are outlined in blue, and visited squares show their move number. Start on the small 5×5 board, then try a full chessboard. Stuck? The hint button applies Warnsdorff's rule, explained below.
Tap any square to place the knight.
The rules
A knight moves in an L: two squares in one direction and one square to the side, jumping over anything in between. A knight's tour is a sequence of such moves that visits every square of the board exactly once. If the last square is one knight move away from the first, so the knight could jump straight back to where it began, the tour is called closed. Otherwise it is open.
Why half the small board is a dead start
On the 5×5 board, where you begin decides everything. We counted every possible tour by computer: there are 1,728 open tours in total, counting each direction separately. This is how many start on each square:
Twelve of the 25 squares have no tour at all. The reason is colour. A knight always lands on a square of the other colour, so a tour alternates light, dark, light, dark. A 5×5 board has 13 squares of the corner colour and only 12 of the other, and a 25-square tour that alternates colours has to start and end on the colour there are 13 of. Start on the other colour and you will run out of squares one short.
The same argument explains why no board with an odd number of squares has a closed tour: a closed tour would need exactly as many squares of each colour.
The trick: Warnsdorff's rule
In 1823 H. C. von Warnsdorff published a simple rule for finding a tour by hand:
Always move to the square from which the knight will have the fewest onward moves.
It works because the squares that are hardest to reach, the corners and edges, get visited while they are still reachable, instead of being left stranded until the end. Warnsdorff's rule is a heuristic, not a proof: when two squares tie, a bad choice can still lead into a dead end. But on a normal chessboard it usually carries you all the way round, and the Hint button above uses exactly this rule. Try it on the 8×8 board.
The knight's tour is a special case of a Hamiltonian path: a route that visits every point exactly once. That is the Starwalk mode in Between Stars, where your aura has to reach every star in a network once. There are no chess rules, just stars and connections, and every level is checked by a solver so it always has a solution.
A thousand years of knight's tours
- 9th century: the earliest known knight's tour appears in the Kavyalankara of the Indian poet Rudrata, a work on poetics. The syllables of a verse are laid out on half a board so that they can be read following the steps of a knight.
- Before 1700: the Indian scholar Nilakantha writes down a fully symmetric closed tour, at least 60 years before Euler's work.
- 1759: Leonhard Euler, who had already solved the Seven Bridges of Königsberg, becomes one of the first mathematicians to study the knight's tour.
- 1823: H. C. von Warnsdorff publishes his rule, the first general procedure for finding a tour.
- 1978: Georges Perec uses a knight's tour on a 10×10 grid to set the order of the chapters in his novel Life: A User's Manual.
- 1991: Allen Schwenk settles which rectangular boards have a closed tour at all.
How many tours are there?
Far more than anyone could try by hand. On the standard 8×8 board there are exactly 26,534,728,821,064 closed tours if each direction counts separately, or 13,267,364,410,532 if a tour and its reverse count as one. The 6×6 board has 9,862 closed tours, and the 5×5 board has none, only the 1,728 open tours counted above.
Schwenk's theorem says exactly which boards allow a closed tour. For a board of m by n squares with m no larger than n, a closed tour exists unless both sides are odd, or the shorter side is 1, 2 or 4, or the board is 3 by 4, 3 by 6 or 3 by 8. So the standard chessboard works, and so does every larger square board with an even side.
Squares, stars and graph theory
Draw a dot for every square and a line between every two squares a knight can jump between, and the chessboard turns into a network. A knight's tour is then a path through that network that visits every dot once, which mathematicians call a Hamiltonian path. For most networks this is a hard problem with no quick rule, which is exactly what makes such puzzles interesting. The knight's graph is a friendly exception: its regular shape makes tours possible to find quickly, even on huge boards.
It is the opposite kind of puzzle to the Seven Bridges of Königsberg, where every line has to be used once and a simple count decides everything. Our guide to one line puzzles explains that side, and the Königsberg article tells the story behind it.
Tips for solving it by hand
- Start in a corner. Corners have only two exits, so they are the hardest squares to fit in later.
- Clear the edges early. Work round the outside first and keep the well-connected middle for later, when you need room to manoeuvre.
- Count onward moves. Before each jump, check how many exits each candidate square will have left and pick the smallest. That is Warnsdorff's rule.
- Watch for orphans. If an unvisited square has lost all its unvisited neighbours, the tour is already lost. Undo until it is reachable again.
Visit every star once
Between Stars is a calm puzzle game for iPhone with two modes: Starwalk, where you visit every star exactly once like a knight's tour, and Bridges, where you cross every connection once. No ads, no timers, undo as often as you like, and every level is solvable.
Free to download for iPhone with iOS 16 or later. No ads, no subscription.
Questions
What is a knight's tour?
A sequence of chess knight moves that lands on every square of the board exactly once. If the knight could jump from the last square straight back to the first, the tour is called closed; otherwise it is open.
Is there a trick to solving the knight's tour?
Yes. Warnsdorff's rule from 1823: always move to the square from which the knight has the fewest onward moves. It makes you visit awkward corner and edge squares while they are still reachable, and on a normal chessboard it usually leads to a complete tour.
How many knight's tours are there on a chessboard?
There are 26,534,728,821,064 closed tours on an 8×8 board if each direction counts separately, or 13,267,364,410,532 if a tour and its reverse count as one. The number of open tours is larger still.
Why can't I finish a 5×5 tour from some squares?
A knight always changes square colour. The 5×5 board has 13 squares of the corner colour and 12 of the other, and a tour of all 25 squares has to start and end on the colour with 13. From any of the other 12 squares, no tour exists.
Which boards have a closed knight's tour?
By Schwenk's theorem from 1991, an m×n board with m no larger than n has a closed tour unless both sides are odd, the shorter side is 1, 2 or 4, or the board is 3×4, 3×6 or 3×8. The 8×8 chessboard has one, the 5×5 board does not.
What does the knight's tour have to do with graph theory?
If every square is a point and every knight move a line, a knight's tour is a path that visits each point exactly once, called a Hamiltonian path. For general networks finding one is famously hard, but the knight's graph is regular enough that tours can be found quickly.
Sources
- Knight's tour (history, Warnsdorff's rule, Schwenk's theorem, number of tours) – Wikipedia
- Hamiltonian path problem – Wikipedia
- Knight's Tour – Wolfram MathWorld
The 5×5 counts (1,728 open tours in total, and how many start on each square) come from our own exhaustive search.