Hash Collision Probability Calculator
Estimate the probability of at least one hash collision (birthday problem) given the number of possible hash values and the number of items hashed.
Common values: 32, 64, 128, 160, 256, 512
How many distinct items are hashed
Fill in the fields and click Calculate.
Formula
Birthday Problem (Exact):
P(collision) = 1 − ∏k=0n−1 (1 − k / H)
where H = 2b is the number of possible hash values for a b-bit hash.
Approximation (accurate when n ≪ H):
P(collision) ≈ 1 − e−n(n−1) / (2H)
Items needed for 50% collision probability:
n50% ≈ √(2H · ln 2) ≈ 1.1774 · √H
Expected number of colliding pairs:
E[collisions] ≈ n(n−1) / (2H)
Assumptions & References
- Hash outputs are assumed to be uniformly distributed across all 2b possible values.
- The birthday approximation P ≈ 1 − e−n²/(2H) is used for numerical stability with large hash spaces; it is accurate to within 1% when n ≤ 0.1·√H.
- Calculations are performed in log-space to handle hash sizes up to 512 bits without floating-point overflow.
- A "collision" means at least two of the n items share the same hash value.
- This does not account for cryptographic weaknesses or non-uniform distributions in real hash functions.
- References: Flajolet & Odlyzko (1990), "Random Mapping Statistics"; NIST FIPS 180-4 (SHA family); Knuth, The Art of Computer Programming, Vol. 2, §6.4.