TL;DR
A breakdown shows a compact binary encoding that represents a full chess position in about 26 bytes. The scheme starts from a naive 24-byte piece-location encoding and then reclaims bits for captures, castling and en passant by exploiting unique board constraints; promotions are packed using a combinatorial ordering trick.
What happened
The author begins from a straightforward representation: list all 32 pieces and record each piece’s square as a 6-bit value (64 squares), yielding 192 bits or 24 bytes. Additional state — captures, castling rights, en passant targets and pawn promotions — initially appears to add roughly 100 bits (~12 bytes). The post then applies optimizations that exploit chess constraints. Because no two pieces share a square, certain metadata can be encoded implicitly by reserving particular piece positions (for example, using a king’s or rook’s expected square to signal captures or castling availability) and thereby reclaiming bits for free. Promotions are encoded by mapping promoted pawns to small integers, sorting those values to produce a unique canonical string, and storing the resulting combinations in 9 bits per side (495 distinct patterns). After these steps the total rises from 24 bytes for piece positions to roughly 26 bytes overall. The write-up includes links to runnable code on Replit and a GitHub repository and notes origins in a Recurse Center presentation.
Why it matters
- Demonstrates how domain constraints (no overlapping pieces, fixed home squares) can compress state without extra storage.
- Offers a reproducible, low-level encoding that could reduce memory or bandwidth for storing positions or transmitting game state.
- Highlights combinatorial techniques (ordering and counting distinct promotion patterns) as a way to minimize bits.
- Serves as an example of how classical compression ideas can be applied to structured, rule-based data like chess positions.
Key facts
- Naive piece-list encoding: 32 pieces × 6 bits = 192 bits = 24 bytes.
- Initial bookkeeping for captures, castling, en passant and promotions was estimated at 100 bits (~12 bytes) before optimizations.
- Captures, castling availability and en passant target can be encoded without additional bits by reusing piece-square information under certain conventions.
- Promotions are encoded per pawn with 3 bits each in the first analysis (48 bits across 16 pawns).
- By mapping promotions to small integers and sorting to form a canonical sequence, the set of promotion states per side fits in 9 bits (495 distinct strings).
- After reclaiming bits and compressing promotions the extra metadata totals about 18 bits (~2 bytes), producing an overall size around 26 bytes.
- The post references Forsyth-Edwards Notation (FEN) as a fuller format that also stores active color, half-move clock and full-move number.
- Author provides runnable code on Replit and a GitHub repository linked from the post.
What to watch next
- Whether this encoding is adopted in practical chess engines or network protocols: not confirmed in the source.
- Compatibility and interoperability with existing formats like FEN or PGN in real systems: not confirmed in the source.
Quick glossary
- en passant: A special pawn capture that is only available on the move immediately after an opponent advances a pawn two ranks from its starting square.
- castling: A king-and-rook move that transfers the king two squares toward a rook and the rook to the square the king crossed; availability depends on prior moves of the king or rook and on intervening squares.
- promotion: When a pawn reaches the farthest rank it is exchanged for a queen, rook, bishop, or knight.
- bit/byte: A bit is the basic unit of digital information (0 or 1); eight bits make one byte.
- Forsyth-Edwards Notation (FEN): A standard ASCII notation for describing a chess position that includes piece placement, active color, castling rights, en passant square, half-move clock and full-move number.
Reader FAQ
How does the scheme reach about 26 bytes?
Start with 24 bytes for all piece squares (32 pieces × 6 bits). Then reclaim bits for captures, castling and en passant by encoding them implicitly via piece positions, and compress promotions into 9 bits per side; the result is roughly 26 bytes total.
Are captures and castling explicitly stored?
They are not separately stored; the method reuses piece-square information (for example, expected king or rook squares) to represent those states.
Is there working code to try this?
Yes — the post links to a Replit example and a GitHub repository.
Does the encoding include half-move and full-move counters?
not confirmed in the source

How to store a chess position in 26 bytes using bit-level magic Author's note: This post was adapted from a presentation at the Recurse Center. Hacker News comments here. This…
Sources
- How to store a chess position in 26 bytes (2022)
- How to store a chess position in 26 bytes using bit-level …
- Storing chess position in 24 Bytes
- Magic Bitboards
Related posts
- Cochrane review: Exercise may ease depression nearly as well as therapy
- Scientists Find Oldest Known Arrow Poison on Arrows Dated to 60,000 Years
- Agonist-Antagonist Myoneural Interface Restores Proprioception to Prosthetic Users