DevTools Logo

Birthday Paradox Hash Collision Calculator

Birthday Paradox Hash Collision Calculator

Collision probability for any hash size or value space, computed in log space so it stays accurate for tiny and huge numbers.

Runs in your browser
Try an example

Parameters

64

N = 2^64 = 18446744073709551616

Result

Assumes every value is equally likely. Skewed or non-random keys collide earlier.

Chance that at least two records share a value

49.9871%

About 1 in 2. P(no collision) = 5.0013e-1

Records needed for a target probability

ProbabilityRecords
1e-9192,077 (approx.)
1e-66,074,003 (approx.)
1%608,926,881 (approx.)
50%5,056,937,541 (approx.)
99%13,034,599,790 (approx.)

50% needs about 1.1774 · √N = 5,056,894,494 records.

Common hash sizes

HashBits50% threshold
CRC-323277,163
UUID v4 (random bits)1222.715e+18
MD51282.172e+19
SHA-11601.423e+24
SHA-2562564.007e+38

Examples

64-bit threshold

Input
calculateBirthdayParadox(64, 5_056_000_000)
Output
fiftyPercentRecords ≈ 5.056e9, collisionProbability ≈ 0.50

At the √(2 ln 2 × 2^64) threshold the collision chance is one half by construction.

32-bit saturation versus the 63% crossover

Input
calculateBirthdayParadox(32, 2 ** 32).collisionProbability
calculateBirthdayParadox(32, 92682).collisionProbability
Output
> 0.999 (saturated)
≈ 0.632 (λ ≈ 1)

Filling the whole 32-bit space guarantees a collision; the 1 − 1/e point sits far below it at ~92k records.

About this tool

Birthday Paradox Hasher computes the collision probability for a b-bit hash over n records with calculateBirthdayParadox (aliased as birthdayParadox), returning { bits, records, space, collisionProbability, collisionPercent, fiftyPercentRecords, fiftyPercentLog10 }. Bit sizes are clamped to 16–512 (rounded, so 1024 becomes 512 and 1 becomes 16) and record counts are sanitized (negatives and NaN become 0, Infinity becomes Number.MAX_VALUE). The hash space is 2^bits, and the 50%-collision threshold is √(2 ln 2 × space), which for 64 bits lands at ≈5.056e9 records.

Probability uses two paths: when bits < 53, n < space, and n ≥ 2, small populations (whole part ≤ 100,000) accumulate the exact log-survival sum Σ log1p(-i/space) with -expm1 for precision; everything else uses the Poisson-style approximation λ = n²/(2 × space) with probability 1 − e^(−λ) (saturating to 1 once λ > 37). Zero or one record always yields 0. A fully populated 32-bit space (2^32 records) therefore saturates to 1, while the classic ~63.2% (1 − 1/e) crossover for 32 bits sits near 92,682 records where λ ≈ 1.

Results stay finite even for extreme inputs: Infinity records map to Number.MAX_VALUE, the threshold is capped at Number.MAX_VALUE, and non-finite probabilities are coerced into [0, 1]. fiftyPercentLog10 gives the base-10 log of the threshold for axis labeling when the raw threshold exceeds readable magnitudes.

How to use this tool

  1. Pick a hash width and population

    Enter bits (clamped to 16–512) and a record count. Read collisionProbability (0–1) and collisionPercent for the headline risk.

  2. Read the 50% threshold

    Use fiftyPercentRecords (≈5.056e9 for 64-bit) as the population where a collision becomes likelier than not; fiftyPercentLog10 helps place it on log axes.

  3. Interpret saturation correctly

    Populations near or above the space size report ~1 (a full 32-bit space is >0.999). For the textbook 63% point, probe λ ≈ 1 instead — about 92,682 records at 32 bits.

Use cases

Sizing hash widths for IDs

Check whether 32, 64, or 128 bits keep the collision risk negligible at an expected record count before choosing an ID scheme.

Explaining the birthday bound

Show why collisions arrive near √(space) rather than near space — e.g. 50% at ~5.06e9 for 64-bit hashes.

Reviewing deduplication risk

Quantify the chance that two content hashes collide in a store, cache, or fingerprint index at current scale.

Common mistakes

Mistake:Expecting 2^32 records in 32 bits to give 63%.

Fix:That population overshoots λ ≈ 1 by billions: λ = n²/(2N) is astronomically large, so the probability saturates to 1. Probe ~92,682 records for the 0.632 point.

Mistake:Passing bits outside 16–512 and expecting them verbatim.

Fix:Bits are rounded and clamped, so 1024 reports bits: 512. Read the returned bits field and compare thresholds at the clamped width.

Mistake:Reading collisionProbability as a percentage.

Fix:The 0–1 fraction is collisionProbability; multiply by 100 (or read collisionPercent) before presenting it with a % sign.

Frequently asked questions

What does this tool do?

It computes the hash-collision probability for a b-bit hash over n records with calculateBirthdayParadox, reporting the clamped bits, the 2^bits space, the 0–1 probability plus percent, and the 50%-collision threshold with its base-10 log.

Why does a full 32-bit space report ~1 instead of 0.632?

2^32 records overshoot the λ = n²/(2N) ≈ 1 crossover by billions, so the probability saturates past 0.999. The textbook 1 − 1/e ≈ 0.632 point sits far below it at ~92,682 records; zero or one record always reports exactly 0.

Is my data uploaded or stored?

No. The exact log-survival sum and the Poisson approximation are pure client-side math — bits and record counts never leave your device.

Where is the 50% threshold, and what bit widths are allowed?

The threshold is √(2 ln 2 × space), about 5.056e9 records for 64-bit hashes. Bit widths are rounded and clamped to 16–512, so 1024 reports bits: 512 — always read the returned bits field.

References & standards