Number of Unique Legal Positions (NULP)
in chess endgames

Updated on 2025-03-05

Kirill Kryukov

About | Introduction | Definitions | Numbers | History | References

About

In this document we describe NULP (Number of Unique Legal Positions) as the measure of state-space complexity of chess endgames. We discuss the definitions of uniqueness and legality, and share the NULP values of various endgames.

This paper gets updated when we get new ideas or results. This work is in public domain using the CC0 license. Please email any questions, comments, and ideas to kkryukov@gmail.com. Especially welcome are confirmations or corrections of any results.


Introduction

In 1950 Claude Shannon famously estimated the number of possible chess positions to be "of the general order of 64!/32!(8!)2(2!)6, or roughly 1043" (Shannon (1950) "Programming a Computer for Playing Chess"). This includes some illegal positions (e.g., pawns on the first rank, both kings in check) and excludes legal positions following captures and promotions. Later estimates include 1050 by Victor Allis (with upper bound of 5x1052). More recently John Tromp has shown the upper bound of 2155 (about 1046.7). Significantly improving the estimate for the whole game is difficult with today's methods and computers, however much better estimates are possible for subsets of the game, such as opening of endgame.

On the opening side, one well-known statistic is Perft, which is the number of move paths of N plies from the starting position. Perft is known for up to 15 plies and is widely used for testing and benchmarking move generators. There are 20 move choices in the starting position, so 20 different legal positions can occur after white's first move, and 400 after black's first reply. These numbers agree with Perft(1) and Perft(2), respectively. Perft(3), however, is larger than the number of different legal positions, because it counts transpositions independently from each other. The number of transpositions grows rapidly with each extra ply. This means that while Perft can be used as the upper bound for the number of positions, it does not provide a very good estimate. I'm not aware of any efforts to count different legal positions beyond the first 2 plies.

On the endgame side most of the estimates of endgame sizes come from solving projects. Strongly solving an endgame typically involves storing a value for each indexed position, thus endgame size can be measured as the number of indexed positions. The choice of the indexing method is crucial here and has to balance database compactness with indexing speed: storing fewer positions makes the database more compact, but complicates the indexing, degrading performance. As the result common indexing method use relaxed concepts of position legality and uniqueness.

In summary, currently available estimates of endgame sizes suffer from following limitations:

In this experiment I aim to advance on all of these points. This means providing more accurate estimates for endgame sizes in chess and chess variants, while trying to avoid illegal and redundant positions when possible. The motivations for computing such estimates include:

At first this data was a by-product of solving experiments, but then I decided to share it separately from solving results.


Definitions

Position

For the purpose of this experiment a position is defined as a combination of piece placement, side to move, castling rights and en-passant rights. Storing the evaluations for all such positions from a particlar endgame allows perfect play from the point of entering that endgame, so the number of such positions is directly related to the amount of necessary storage space.

A complete game state should include the move counter for detecting a draw by 50-move rule. Move counter can be very important when distance to mate (DTM) is stored in the database and used for choosing the moves. However using distance to zeroing (DTZ) allows to avoid storing the move counter while still respecting the 50-move rule. (Most of endgame databases in use today simply ignore the 50-move rule, in which case the move counter is also unnecessary).

A complete game state should also include the relevant part of game history for detecting 3-fold repetitions. Repetitions can't occur in a winning line if the winning side plays perfectly, and they won't matter in a drawing line, therefore the history can be safely omitted as well.

Uniqueness

Counting, solving or storing the same position twice is obviously a waste of time and space. Similarly, if two positions can be proven to produce identical outcomes with best play of both sides (let's call such positions equivalent), it's a waste of space to store both of them independently. Whether it's also a waste of time depends on how fast the equivalence can be tested and on how it impacts indexing design and performance.

In this experiment I require equivalence to perfectly take into account board mirroring, board rotation and color swapping. Such equivalence is easy to test, so counting unique positions (or equivalence classes) is possible. (It's less trivial to design a gapless indexing scheme omitting all redundant positions, but this is outside of the scope of current experiment).

Two positions are called equivalent if one can be obtained from the other through a sequence of transformations, which may include:

 1. Swapping colors of all pieces, mirroring locations of all pieces and en-passant target squares around the horizontal middle line, swapping castling rights and side to move:
k3/4/4/KR2 w
white to move
kr2/4/4/K3 w
black to move
 2. (Only for positions with no castling rights, except on a board of odd width) Mirroring locations of all pieces and en-passant rights around the vertical middle line.
k3/4/4/KR2 w
white to move
3k/4/4/2RK w
white to move
 3. (Only for pawnless positions with no castling rights) Mirroring locations of all pieces around the horizontal middle line.
k3/4/4/KR2 w
white to move
KR2/4/4/k3 w
white to move
 4. (Only for pawnless positions with no castling rights, only for square board) Mirroring locations of all pieces around the a8-h1 diagonal (or around the line connecting top-left and bottom-right corners for other board sizes).
k3/4/4/KR2 w
white to move
k2K/3R/4/4 w
white to move

Rotations and mirroring around the other diagonal can be produced by combining several of the listed transformations. Also you can notice that this equivalence is reflexive, symmetric and transitive.

The 4-th transformation can produce identical position if all pieces are located on the a8-h1 diagonal. The 2-nd and 3-rd transformations can produce identical positions on an odd-sized board. The 1-st transformation however can be applied to any position, and will always produce a non-identical position. Therefore every position has at least one equivalent non-identical variant. Each transformation applied twice returns back to the original position, so the maximum possible number of equivalent non-identical variants for a position is 16.

Here is one example of equivalence class — all these positions are considered to be equivalent to each other (4x4 board is used for compactness):

k3/4/4/KR2 w
white to move
3k/4/4/2RK w
white to move
KR2/4/4/k3 w
white to move
2RK/4/4/3k w
white to move
4/4/R3/K2k w
white to move
K2k/R3/4/4 w
white to move
4/4/3R/k2K w
white to move
k2K/3R/4/4 w
white to move
K3/4/4/kr2 w
black to move
3K/4/4/2rk w
black to move
kr2/4/4/K3 w
black to move
2rk/4/4/3K w
black to move
4/4/r3/k2K w
black to move
k2K/r3/4/4 w
black to move
4/4/3r/K2k w
black to move
K2k/3r/4/4 w
black to move

Counting unique positions means counting such equivalence classes (or counting only one position out of each equivalence class).

One case of trivial equivalence ignored in the definition above is between two positions that differ by just en-passant capture right, when the en-passant capture is not a legal move. Such two positions have identical sets of available moves, so it's redundant to solve or store both of them. However in this experiment I count such positions separately.

Legality

Traditionally legal positions are defined as those that can be reached from the starting position after a sequence of legal moves. Checking for such legality is prohibitively expensive, so more simple concepts of legality are used in endgame solving. Such legality is easy to verify, but can include some positions that are illegal in traditional sense. Here is the definition used in this experiment:

A position is called illegal when any of the following conditions holds:

All other positions are considered to be legal and counted in this experiment (none of the illegal positions are counted).


Numbers

NULP in chess

The number of unique legal positions in chess endgames with 8 or fewer pieces is 38,603,956,906,065,185.

The following table and chart show the NULP for each number of pieces.

PiecesPositions
2 462 (*)
3 368,079 (*)
4 125,246,598 (*)
5 25,912,594,054 (*)
6 3,787,154,440,416 (*)
7 423,836,835,667,331 (*)
838,176,306,877,748,245 (*)
Chess NULP

This sequence is the start of OEIS sequence A318266 [OEIS-A318266].

The numbers link to text files with NULP for each endgame. The asterisks link to text files with NULP for each ESM. The definition and notation for endgames and ESM are discussed in "Counting Chess Endgames".

Largest endgames

PiecesPawnlessWith pawns
EndgameSizeEndgameSize
2kk462
3knk53,806kpk165,676
4kbnk3,067,466knpk9,699,457
5kbnkn175,863,026knpkn556,739,460
6krbnkn9,488,822,935kbnpkn30,803,735,265
7krbnkbn512,840,231,278kbnpkbn1,670,865,014,596
8kqrbnkbn25,192,079,591,272krbnpkbn87,076,702,767,652

Castling

Endgames with castling rights are extremely rare, so they are typically ignored in endgame solving. The next table shows the number of Chess positions with castling rights with up to 8 pieces. The numbers in parentheses and the chart show proportion of such positions.

PiecesPositions with
castling rights
2 0 (0.000%)
3 211 (0.057%)
4 113,158 (0.090%)
5 29,955,209 (0.116%)
6 5,216,780,406 (0.138%)
7 672,112,496,048 (0.159%)
868,300,985,290,716 (0.179%)
Proportion of Chess positions with castling rights

As expected, very few endgame positions have castling rights: about 0.1% of all positions with 4 or 5 pieces. The proportion is slowly increasing with extra pieces, probably reaching 0.2% with 10 pieces.

Clearly space saving consideration alone can't justify the exclusion of these positions from solving. The extra effort required for implementing the indexing of these positions is likely the main reason why these positions are usually omitted. Since loss of the castling right is irreversible, it's possible to construct a separate database for just positions with castling rights, which can be used alongside with existing endgame database.

En passant capture

How many chess positions have en passant capture rights? Here are the numbers for up to 8 pieces.

PiecesPositions with
en-passant capture rights
2 0 (0.000%)
3 0 (0.000%)
4 23,017 (0.018%)
5 11,960,101 (0.046%)
6 3,066,498,815 (0.081%)
7 517,042,047,128 (0.122%)
864,468,257,617,466 (0.169%)

En passant capture and castling

How many positions have both en passant capture and castling rights? How many have just castling or just en passant? How many have none? Here are the numbers for up to 8 pieces ('C' = castling rigths, 'E' = en passant capture rights). Numbers link to text files with NULP for each endgame, asterisks link to text files with NULP for each ESM.

PiecesPositions
CEE&C
2 462 (*) 0 (*) 0 (*) 0 (*)
3 367,868 (*) 211 (*) 0 (*) 0 (*)
4 125,110,423 (*) 113,158 (*) 23,017 (*) 0 (*)
5 25,870,681,552 (*) 29,952,401 (*) 11,957,293 (*) 2,808 (*)
6 3,778,872,612,577 (*) 5,215,329,024 (*) 3,065,047,433 (*) 1,451,382 (*)
7 422,648,050,983,625 (*) 671,742,636,578 (*) 516,672,187,658 (*) 369,859,470 (*)
838,043,599,567,172,213 (*)68,239,052,958,566 (*)64,406,325,285,316 (*)61,932,332,150 (*)

The next table shows the proportion of positions with/without en passant and castling rights among all positions with the same number of pieces. The chart compares columns 'C' and 'E'.

PiecesPositions, %
CEE&C
2100.0000.0000.0000.000
3 99.9430.0570.0000.000
4 99.8910.0900.0180.000
5 99.8380.1160.0460.000
6 99.7810.1380.0810.000
7 99.7200.1580.1220.000
8 99.6520.1790.1690.000
Proportion of Chess positions with castling rights compared with proportion of positions with en passant capture rights

Positions with castling rights are more abundant than those with en passant, when the number of pieces is 8 or less. However it's safe to say that from 9 pieces the relation reverses.

Chess960

Chess960 (Fischer Random Chess) is a popular chess variant featuring additional starting positions. From endgame solving point of view its only difference from Chess is that many more positions can potentially have castling rights:

PiecesChess960 positions
with castling rights
Chess960/Chess
2 0 (0.000%)
3 4,420 (1.187%)20.948
4 2,385,912 (1.871%)21.085
5 635,808,642 (2.398%)21.225
6 111,477,502,856 (2.863%)21.369
7 14,460,843,451,896 (3.304%)21.516
81,479,698,416,937,946 (3.738%)21.664
Proportion of positions with castling rights (Chess and Chess960)Chess960/Chess ratio for the number of positions with castling rights

Chess960 has more than 20 times more positions with castling rights than Chess. With 7 pieces already over 3% of Chess960 positions have castling rights, which is insane compared to Chess. Here space and time saving can be an argument for omitting such positions, however this way we'll miss more than 3% of beauty and complexity of Chess960 endgames, which weddcccccc see as a big loss. The Chess960/Chess ratio of the number of positions with castling rights is remarkably stable around 21-22, and is slowly increasing with extra pieces, almost perfectly linearly.

Using the castling data above it's easy to find the number of Chess960 positions:

PiecesChess960 positions
2 462
3 372,288
4 127,519,352
5 26,518,447,487
6 3,893,415,162,866
7 437,625,566,623,179
839,587,704,309,395,475

Chess960 is a superset of Chess: every Chess position exists in Chess960, but not the vice versa - some Chess960 positions are not found in Chess. The following table/figure shows the proportion of Chess960 endgame positions overlapping with Chess.

PiecesAmong Chess960 positions
% in Chess% not in Chess
2100.0000.000
3 98.8691.131
4 98.2181.782
5 97.7152.285
6 97.2712.729
7 96.8493.151
8 96.4353.565
Overlap between Chess and Chess960

History

April 14, 2014
Counted 8-piece positions with/without en passant and castling rights.
April 11, 2014
Counted positions with/without en passant and castling rights, for up to 7 pieces.
January 6, 2014
The number of Chess960 positions with 8 pieces is 39,587,704,309,395,475. This is 1.037 times larger than in Chess.
December 27, 2013
The number of Chess positions with 8 pieces is 38,176,306,877,748,245 (38 quadrillion), about 90 times larger than with 7 pieces.
February 28, 2013
Counted positions with castling rights and up to 7 pieces in Chess and Chess960.
February 24, 2013
Web-site created, with NULP values for chess endgames with up to 7 pieces.

References

OEIS-A318266. OEIS Foundation Inc. (2025). The On-Line Encyclopedia of Integer Sequences, Published electronically at https://oeis.org, Sequence A318266. https://oeis.org/A318266.