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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A Zobrist hash is a compact fingerprint of a chess position, not a guaranteed-unique ID. Engines use it to find cached search results and, in some implementations, help detect repeated positions. For a chess database that must identify positions without ambiguity, store and compare a canonical position representation as well; do not rely on a Zobrist key alone.

What does a Zobrist hash represent?

Zobrist hashing assigns pseudorandom bit strings to position features and combines the strings, conventionally with XOR, to create a fixed-width key. For chess, features typically include which piece occupies each square and state that affects legal moves, such as the side to move, castling rights and en-passant availability.

The feature set matters: two boards with identical piece placement can still differ as positions if their legal possibilities differ. Stockfish’s current development source has separate keys for piece-square combinations, castling, en-passant and side information; implementations choose their own tables, widths and details, so keys from different engines are not necessarily interoperable. Stockfish position source

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

Why do chess engines use it?

Different move orders can lead to the same position, a situation called a transposition. Searching that position repeatedly wastes work. A transposition table stores search information associated with a position key so an engine can reuse earlier results or retrieve a move to help order later searches. MIT’s 2018 6.172 lecture summarizes the purpose: “A transposition table stores results of previous searches in a hash table to avoid unnecessary work.” MIT 6.172 Lecture 19

Hashing can also support repetition detection. Stockfish’s position code describes two Zobrist-based hash tables used to detect recurring positions for threefold-repetition draws. That is a separate use from caching search results; an engine’s exact data structures and rules handling are implementation-specific. Stockfish position source

How is a Zobrist key updated after a move?

Instead of rebuilding the key from every feature after every move, an engine can update it incrementally. XOR out the keys for features that cease to apply and XOR in the keys for features that become true. XORing the same value twice cancels it, which also makes undoing moves convenient when the implementation records or reconstructs the relevant state.

Correctness depends on accounting for every changed feature. A move handler must consider:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Moving piece: remove its old piece-square key and add its new one.
  • Capture: remove the captured piece’s key from its square.
  • Promotion: represent the promoted piece on the destination square, not the pawn that arrived there.
  • Castling: update both king and rook squares, as well as any castling rights that are lost.
  • En passant: update the en-passant state when it changes and remove the captured pawn from its actual square.
  • Side to move: toggle the side key after each move.

During development, compare the incrementally maintained key with a full recomputation from the current position after make and unmake operations. This catches omitted state changes and undo bugs before they silently corrupt lookups.

Is a Zobrist key unique enough for a chess database?

No fixed-width hash is mathematically guaranteed to be unique for every possible position. Distinct positions can, in principle, produce the same full Zobrist key. Albert L. Zobrist’s 1970 report already recognized retrieval errors and proposed an auxiliary method to detect them: “An auxiliary method which detects retrieval errors is proposed.” Zobrist, A New Hashing Method With Application for Game Playing (Technical Report 88)

That makes a Zobrist key useful as a fast fingerprint, but unsuitable as the sole proof of identity in an application where a false match would be unacceptable. Store a canonical representation of the position—or enough data to reconstruct and compare it—and verify candidate matches against that representation. Define what “same position” means for your app: piece placement alone is not enough if side to move, castling rights or en-passant state affect the distinction you need.

What are the two kinds of hash collision?

It helps to separate a collision in the key itself from a collision in the table used to store entries.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Case What happens Why it matters
Full-key collision Two distinct positions produce the same fixed-width Zobrist key. A lookup that trusts the key alone can mistake one position for another.
Table-slot conflict Different keys map to the same slot in a finite transposition table. Entries compete for limited space; replacement policy determines which cached information remains.

A slot conflict does not mean the full keys are equal. Robust table implementations may store and compare key fragments or use another validation method, but the exact approach depends on the engine. The table’s replacement strategy is a separate design choice from how the position key is constructed.

Best Value
Chessnut Move – Robotic Chessboard with Plastic Pieces, Self-Moving Pieces Simultaneously, Full Piece Recognition, Built-in Chess Engine, Voice Control & Video Integration
  • 🤖 SELF-MOVING CHESS ON A REAL BOARD - Chessnut Move pairs a wooden chessboard with plastic Automated pieces that automatically move across the board, bringing digital games to life.Move can reposition multiple pieces at once to reset games quickly or build study positions with less setup time.
  • 🎯 1 MM FULL PIECE RECOGNITION - Identifies every piece and its exact board position for accurate move tracking. A 10 Hz refresh rate and 0.1-second response support automated moves averaging under three seconds.
  • 🚂BUILT-IN STOCKFISH ENGINE - Play or practice against built-in engines such as Stockfish directly on Chessnut Move, with adjustable Elo difficulty and no phone, computer, or app required.
  • 📹VIDEO & ENDGAME IMPORT VIA APP - Connect to the Chessnut App to import positions or replay tutorial and tournament moves automatically on the physical board. Practice endgames, openings, and tactics with minimal setup.
  • 🔗ONLINE PLAY WITH AUTO RESPONSES - Connect through the Chessnut App to Chess-com, Lichess, and other supported platforms; your opponent's moves are automatically played on the physical board.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How likely are full-key collisions?

There is no authoritative, generally applicable modern collision-rate figure established by the sources cited here. Risk depends on key width, how many positions are considered, how the key is constructed and whether the concern is a full-key match or a table-slot conflict. Avoid treating a rule-of-thumb probability as a guarantee for every engine or database.

When evaluating an implementation, check the key width and validation approach together. For a search cache, a small residual risk may be an accepted engineering trade-off; for persistent database identity or any workflow where a false match has serious consequences, verify the full position representation.

Does a larger Stockfish Hash setting change the key?

No. The Hash setting controls memory allocated for cached search data, not the meaning of the Zobrist construction. Stockfish expresses Hash in MiB, and its FAQ says the value need not be a power of two. Its suggested allocations vary with time control, thread count and analysis depth, with larger allocations suggested for longer analysis when system memory allows; these are Stockfish-specific guidelines, not universal settings. Stockfish FAQ

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

More table memory can let an engine retain more search information, but it cannot make a finite-width key unique or repair an incorrect incremental update.

What should you compare when choosing or building an implementation?

  • Key width and verification: How many bits are retained, and does the lookup validate a candidate rather than blindly trusting a key match?
  • Represented state: Are side to move, castling rights and en-passant state included alongside piece placement?
  • Update correctness: Are make/unmake updates tested against a full recomputation?
  • Table design: What does each entry store, and how does the engine choose which entry to replace?
  • Workload and memory: Is the structure serving short searches, deep analysis, repetition detection or persistent database lookups?

For broader game-AI treatment of Zobrist keys, incremental hashing, transposition-table contents and replacement strategies, see Artificial Intelligence for Games, 2nd Edition. It covers game AI broadly rather than serving as 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.