Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › chess engines

Zobrist Hashing in Chess Engines: What It Is, How It Works, and Can You Rely on It?

By Freedom251 Team · · 4 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Zobrist key is a compact fingerprint of a chess position, not a guaranteed unique ID. Chess engines use it to look up cached search information and, in some implementations, help detect repeated positions. For a chess-database app, it can be useful as a fast index, but it should not be the sole proof that two records represent the same position.

What does a Zobrist hash represent?

Zobrist hashing assigns pseudorandom bit strings to position features and combines the strings—usually with XOR—to create a fixed-width key. In chess, those features commonly include the piece occupying each square, whose turn it is, castling rights, and en-passant availability. The last three matter because they can change which moves are legal even when the pieces occupy the same squares.

As an Amazon Associate I earn from qualifying purchases.

Implementations choose their own random tables, key widths, and feature details, so keys from different engines are not necessarily interchangeable. Stockfish’s current position implementation includes keys for piece-square combinations, castling, and en-passant, as well as side-to-move information. Its source is version-sensitive: Stockfish position implementation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why do chess engines use Zobrist keys?

Finding transpositions

A transposition happens when different move orders reach the same position. An engine can store results from an earlier search and consult them when that position appears again, avoiding duplicated work or using a previously found move to guide search ordering. MIT’s 2018 6.172 lecture explains: “A transposition table stores results of previous searches in a hash table to avoid unnecessary work.” MIT 6.172, Lecture 19: Leiserchess Codewalk.

Detecting repeated positions

Position hashing can also support repetition detection. Stockfish’s position source describes two Zobrist-based hash tables used to help detect positions recurring for threefold-repetition draws. That is a separate use from caching search results: an engine may use related position fingerprints in different data structures for different purposes.

How is the key updated when a move is made?

XOR makes incremental updates practical. XOR the keys for features that disappear out of the position, then XOR in keys for features that appear. Because XORing the same value twice cancels it, the operation can also be reversed during unmake-move—provided every state change is accounted for.

For each move, an implementation needs to handle the affected piece-square features and any changed state, including:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Captures: remove the captured piece’s square feature as well as the moving piece’s old feature.
  • Promotions: replace the pawn feature with the promoted piece’s feature on the destination square.
  • Castling: update both king and rook squares, along with any castling rights that change.
  • En passant: account for the captured pawn on its actual square and update en-passant availability.
  • Side to move: toggle the side feature after every legal move.
  • Rights and state changes: remove old castling or en-passant state keys and add the new applicable keys.

During development, compare the incrementally maintained key with one recomputed from the complete position after make and unmake operations. This catches omissions in edge cases before they cause incorrect table lookups.

Is a Zobrist key unique enough for a chess database?

No finite-width Zobrist key is mathematically guaranteed to be unique. Two distinct positions can produce the same full key; that is a full-key collision. Separately, a transposition table has a limited number of slots, so different full keys can map to the same slot; that is a table-slot conflict. The latter can happen even when the keys themselves differ.

These risks require different handling. A table-slot conflict is managed by table design, such as comparing a stored key fragment or replacing an entry according to an engine-specific policy. A full-key collision requires stronger identity checking if a false match would be unacceptable—for example, comparing a canonical representation of the position after a hash match. The exact safeguards vary by application.

Zobrist’s 1970 report proposed an auxiliary method to detect retrieval errors: “An auxiliary method which detects retrieval errors is proposed.” Albert L. Zobrist, “A New Hashing Method With Application for Game Playing,” University of Wisconsin Technical Report 88. The available sources do not establish one authoritative modern collision probability that applies to every engine or database. Any estimate depends on key width, the number of positions considered, how keys are constructed, and whether the concern is a full-key collision or a slot conflict. For an archival or correctness-critical database, use the hash as a fast filter or index, then verify identity with position data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What does the engine’s Hash setting change?

A transposition table consumes memory to retain search data. In Stockfish, the Hash setting is expressed in MiB, and its official FAQ says the size need not be a power of two. Its guidance varies with time control, thread count, and analysis depth; it recommends larger allocations for longer analysis, subject to available system memory. Those are Stockfish recommendations, not a universal setting for every engine: Stockfish FAQ: Useful Commands.

Increasing table memory affects how much cached information an engine can retain; it does not change what the Zobrist key represents or make the key collision-proof.

What should you compare when evaluating implementations?

  • Key width and verification: how many bits identify a key, and what the lookup does before trusting a match.
  • Represented state: whether the key includes all features that affect legal possibilities, not just piece placement.
  • Update correctness: whether incremental make/unmake logic agrees with full recomputation across special moves.
  • Table design: what an entry stores and how collisions for limited slots are handled.
  • Memory and workload: how much data is retained and how the table performs for the engine’s search needs.

These are linked design choices rather than a single best configuration. Artificial Intelligence for Games, 2nd Edition covers Zobrist keys, incremental hashing, transposition-table contents, and replacement strategies in its board-games material; it is broader game-AI background rather than a dedicated chess-engine manual.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

chess enginesChess programmingsoftware engineeringTransposition tablesZobrist hashing

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.