xxHash Collision Probability: How Likely Is a Collision?
The odds for XXH32, XXH64, and XXH3 at real collection sizes, the formula behind them, and the point where a fast hash stops being enough.
Quick Answer
The collision probability of xxHash depends on its output size and how many values you hash. For any two different inputs it is about 1 in 4.29 billion for XXH32 and 1 in 18.4 quintillion for XXH64. Across a whole set, the chance of at least one collision reaches 50% at about 77,000 hashes for 32 bits, 5.06 billion for 64 bits, and 22 quintillion for 128-bit XXH3.
Those two kinds of number are easy to mix up. “1 in 4 billion” is the chance that one specific pair collides. A collection of 100,000 items contains about 5 billion pairs, which is why a 32-bit hash that sounds safe is more likely than not to collide at that size. This is the birthday problem, and it applies to every hash function, not just xxHash.
xxHash Collision Probability Table
Chance of at least one accidental collision among n different inputs, assuming the hash spreads its outputs evenly:
| Items hashed | 32-bit (XXH32) | 64-bit (XXH64, XXH3) | 128-bit (XXH3) |
|---|---|---|---|
| 1,000 | 0.012% (1 in 8,600) | 2.7 × 10-14 | 1.5 × 10-33 |
| 10,000 | 1.2% | 2.7 × 10-12 | 1.5 × 10-31 |
| 100,000 | 69% | 2.7 × 10-10 | 1.5 × 10-29 |
| 1 million | ~100% (about 116 colliding pairs expected) | 2.7 × 10-8 (1 in 37 million) | 1.5 × 10-27 |
| 100 million | ~100% | 0.027% (1 in 3,700) | 1.5 × 10-23 |
| 1 billion | ~100% | 2.7% | 1.5 × 10-21 |
| 10 billion | ~100% | 93% | 1.5 × 10-19 |
| 1 trillion | ~100% | ~100% | 1.5 × 10-15 |
The thresholds people usually ask about:
| Output size | One specific pair collides | Items for a 1-in-a-million chance | Items for a 50% chance |
|---|---|---|---|
| 32 bits | 1 in 4.29 billion | about 93 | about 77,000 |
| 64 bits | 1 in 1.8 × 1019 | about 6.1 million | about 5.06 billion |
| 128 bits | 1 in 3.4 × 1038 | about 2.6 × 1016 | about 2.2 × 1019 |
The 32-bit column is not specific to xxHash. CRC32, Adler-32, and any other 32-bit value have the same ceiling, because the limit comes from the number of possible outputs.
The Formula
For n items and a hash with b output bits, the chance of at least one collision is approximately:
p ≈ 1 - e^( -n(n-1) / (2 · 2^b) )While p is small this simplifies to n² / 2^(b+1), which is also the expected number of colliding pairs. Two shortcuts follow from it:
- 50% point: about
1.18 × 2^(b/2)items. That is 1.18 × 65,536 for 32 bits and 1.18 × 4.29 billion for 64 bits. - Ten times the items, a hundred times the risk. The probability grows with the square of the collection size until it gets close to 1.
To get the number for your own collection size, this runs in any Python 3:
import math
def collision_probability(n, bits):
return -math.expm1(-n * (n - 1) / 2 / 2**bits)
print(collision_probability(100_000, 32)) # 0.6878...
print(collision_probability(1_000_000_000, 64)) # 0.0267...expm1 is used instead of 1 - math.exp(...) so that very small probabilities, like the 128-bit ones, do not round to zero.
XXH32, XXH64, XXH3: Which Variant Changes the Odds?
Only the output size does. The xxHash family has four outputs:
- XXH32: 32 bits. Fine for hash tables that handle collisions anyway. Too small to identify content.
- XXH64: 64 bits. Comfortable up to millions of items, measurable risk in the billions.
- XXH3, 64-bit: the same 64 bits and the same accidental collision odds as XXH64. The difference is speed, mostly on small inputs.
- XXH3, 128-bit (XXH128): 128 bits. Accidental collisions are out of reach for any collection you could store.
Truncating gives you the smaller size's odds. If you compute XXH64 and keep only 32 bits to save space in an index, you are back in the 32-bit column of the table.
What the Math Assumes
The table is a best case. It holds when two things are true.
The hash spreads outputs evenly. xxHash is built for this and passes the SMHasher test suite, and its author publishes large collision tests on the project's GitHub wiki. For scale, hashing 100 × 230 (about 107 billion) inputs to 64 bits should produce about 312 colliding pairs from the formula alone. A good 64-bit hash lands near that figure; a weak one produces many more.
Nobody is choosing the inputs. The birthday numbers describe accidents. xxHash is a non-cryptographic hash, and its documentation says so. Someone who wants two different inputs with the same xxHash value can construct them, whatever the output size. A seed makes that harder for an outsider who does not know it, and it does not turn xxHash into a security tool.
Accidental and deliberate collisions are different questions
“Will two of my own files ever clash?” is answered by the table. “Could someone hand me a file that matches a hash I trust?” is not. For the second question the answer for every xxHash variant is yes, in principle, and you need a cryptographic hash such as SHA-256.
When a Collision Matters
The same probability is harmless in one design and data loss in another.
- Hash tables, bloom filters, sharding: collisions are expected and handled. Any variant works; pick on speed.
- Cache keys and change detection: a collision returns stale or wrong data. With 64 bits and millions of keys the risk is around 1 in tens of millions. With 32 bits it is close to certain.
- Deduplication that deletes or hard-links: a collision means a file you needed is replaced by a different one. Do not let the hash be the only evidence. Group by size first, use the hash to find candidates, then confirm with a byte-for-byte comparison or SHA-256 before anything is removed.
- Verifying a download, a backup, or a hand-over: the question includes “has this been altered?”, so use SHA-256.
A practical rule: if a wrong match costs you a retry, 64-bit xxHash is plenty. If a wrong match costs you a file, confirm it.
xxHash vs SHA-256 for File Integrity
SHA-256 produces 256 bits, so its 50% birthday point is around 4 × 1038 items, and it is designed so that finding a collision on purpose is not feasible. No SHA-256 collision has been published. The cost is speed: xxHash is usually many times faster per byte, though on spinning disks and network shares the drive is often the bottleneck, not the hash.
That trade is covered in detail in xxHash vs CRC32 vs SHA-256, and the reasons MD5 is no longer the middle ground are in SHA-256 vs MD5.
Where FolderManifest fits
FolderManifest does not use xxHash. It is a desktop app for Windows 10/11, macOS, and Linux that writes folder manifests and verifies copies with SHA-256 (CRC32 is available for compatibility), and it matches duplicate files by exact SHA-256 content. That is slower than an xxHash scan and it is the choice you want when the result decides whether an original gets deleted or a migration gets signed off. If you need raw speed across a trusted internal pipeline, a command-line tool such as xxhsum is the better fit, and it is free.
- One file: the free Checksum Calculator returns SHA-256, MD5, SHA-1, and CRC32.
- A handful of files: the free Find Duplicates tool takes up to 10 files (10 MB each), hashes them in memory on our server without storing them, and groups exact matches.
- Whole folders and drives: the desktop app hashes on your own machine and saves the result as a manifest you can re-check later.
Frequently Asked Questions
What is the collision probability of xxHash?
It depends on the output size and on how many values you hash. For any two different inputs the chance is about 1 in 4.29 billion for XXH32 and 1 in 18.4 quintillion for XXH64 and 64-bit XXH3. Across a whole set, the chance of at least one collision reaches 50% at about 77,000 hashes for 32 bits, 5.06 billion for 64 bits, and 22 quintillion for 128 bits.
Can xxHash have collisions?
Yes. Every hash with a fixed output size has collisions, because there are more possible inputs than outputs. xxHash is also non-cryptographic, so someone who wants two inputs to collide can construct them. What changes between variants is how many random inputs you can hash before an accidental collision becomes likely.
How many hashes before a 64-bit xxHash collision is likely?
About 5.06 billion values for a 50% chance of at least one collision. At 1 million values the chance is about 1 in 37 million, at 100 million it is about 1 in 3,700, and at 1 billion it is about 2.7%.
Is XXH32 safe for deduplication?
Not on its own. With 10,000 items there is already about a 1.2% chance that two different items share an XXH32 value, and with 100,000 items it is about 69%. Use 32-bit hashes only to find candidates, then confirm with a longer hash or a byte-for-byte comparison.
Does XXH3 have fewer collisions than XXH64?
Not at the same output size. XXH3 in 64-bit mode and XXH64 both produce 64 bits, so their accidental collision odds are the same. XXH3 is mainly faster, especially on small inputs. Its 128-bit mode is the variant that lowers the collision probability.
Is xxHash collision resistant like SHA-256?
No. Collision resistance in the cryptographic sense means nobody can find two inputs with the same hash on purpose. xxHash does not claim that. SHA-256 does, and no SHA-256 collision has been published. Use SHA-256 when the files or the sender are not trusted.
Does FolderManifest use xxHash?
No. FolderManifest supports CRC32 and SHA-256 for manifests and verification, and matches duplicates by exact SHA-256 content. xxHash is not currently supported.
Verify Files With SHA-256, Not a Guess
SHA-256 folder manifests, folder comparison, and exact duplicate detection for Windows, macOS, and Linux. 7-day free trial, no card required, 30-day money-back guarantee.
