Any matching pair, not a fixed target
A collision occurs when at least two outputs take the same hash value. The question concerns any pair among n outputs, not matching a preselected target. The number of pairs grows as n(n−1)/2. That explains why collisions can matter around √M outputs even though the space contains M possible values. The number of pairs is the binomial coefficient “n choose 2”, not n2.[1]
Assume independent uniformly distributed outputs across M equally likely values. For n>M, a collision is certain.[1]
For an idealized b-bit output space, M=2ᵇ. The formula describes a random model rather than automatically testing a specific hash function or implementation. Deliberately repeating identical input gives the same deterministic hash; that is not the modeled event of distinct messages accidentally sharing an output.[1]
Calculate the no-collision probability first
The first output may take any value. If k distinct values are occupied, the next output must hit one of M−k unused values to avoid collision. Conditional on no previous collision, that probability is (M−k)/M. Multiplying these conditional probabilities gives the complement. Pair-collision events themselves must not simply be multiplied as independent events. This applies the product rule for conditional probabilities rather than incorrectly assuming that all pair events are independent.[1]
With independent uniform outputs, two distinct pair-collision events are indeed pairwise independent. That does not make the entire family jointly independent: among three outputs, two equalities already force the third. For M=2, P(E12)=1/2 and P(E12∩E13)=1/4, but P(E12∩E13∩E23)=1/4 rather than (1/2)3. The conditional-product derivation avoids that confusion; the union bound does not require independent pair events in the first place.[1]
The approximation replaces log(1−x) by −x. It is not the same calculation as the exact finite product.[1]
The pair sum provides an upper bound. It is a useful direct approximation only when total probability is small and must not be reported as a probability above 1.[1]
The exponential approximation gives a 50% threshold near n≈√(2M ln 2) when n(n−1) can be approximated by n2. Include the factor √(2 ln 2)≈1.177. √M describes the scale rather than the exact half-probability threshold. For a uniform space with M=2ᵇ outputs, Shannon entropy is b bits. This information quantity describes the output space rather than the collision probability itself.[1]
- Define the event: at least one pair of distinct considered items produces the same value. Assume independent uniform outputs into a space of positive integer size M. The bit-length model uses M=2ᵇ.
- Conditional on k previous outputs being distinct, exactly k values are occupied. The next output avoids collision with probability (M−k)/M. For 0≤n≤M, multiplying all n conditional factors gives the no-collision probability.
- Subtract that complement from one. For n=0 the empty product is one, as it is for n=1; collision probability is zero in both cases. If n>M, the pigeonhole principle forces a collision, giving probability one.
- Only replacing log(1−k/M) by −k/M gives the exponential approximation 1−exp(−n(n−1)/(2M)). The pair sum n(n−1)/(2M) is instead an upper bound. For n=20,M=256, the exact product is about 0.533167, the exponential approximation 0.523929 and the bound 0.742188.
Birthdays and a small hash space
23 people as a familiar random model
- Given
- 23 people with birthdays independently and uniformly distributed across 365 days, ignoring leap days in the model.
- Find
- Compare the exact model formula with its approximation.
No collision means all 23 dates differ.
The exponential approximation uses the sum of 253 pair contributions.
Result: About 50.73% from the exact model formula; the approximation gives about 50.00%.
Check: 253 counts pair events. They are pairwise independent, but not jointly independent as a whole family. The bit-length calculator does not directly cover M=365.
20 outputs with only 8 bits
- Given
- b=8, so M=256, with n=20 independent uniform outputs.
- Find
- Calculate collision probability.
Use factors k=0 through 19.
Compare with the explicitly labeled approximation.
Result: Numerical evaluation of the exact model formula gives about 53.32%.
Check: The pair upper bound is 190/256≈0.742188, noticeably looser than the product calculation.
Recall the method later with the formula’s flashcards.
10 flashcards · English materials
Already have an account? Sign in for flashcardsAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Bit length and count without unstable factorials
The specialized calculator accepts integer bit lengths from 1 to 256 and integer counts from 0 to 106. It numerically evaluates the exact finite-product formula rather than only the birthday approximation. It sums log1p terms with compensation and recovers probability using −expm1. This preserves very small representable probabilities that direct 1−exp(…) evaluation could round to zero.[1]
For n=0 or n=1, probability is zero. For n>2ᵇ it is exactly one. Otherwise an extremely high probability can numerically round to one while the mathematical model retains a tiny no-collision probability. Distinguish that rounded one from the guaranteed pigeonhole case.[1]
Counts, boundaries and random assumptions
Calculate · Foundation
b=2 and n=3. Calculate exact collision probability.
Show hint
There are four outputs and three factors.
Learning goal: Evaluate the product exactly for a small space.
Show solution and calculation
p=1−1·(3/4)·(2/4)=1−3/8=5/8=0.625.
Interpret · Foundation
What is p for b=8 with n=0, n=1 and n=257?
Show hint
No pair versus more outputs than values.
Learning goal: Handle model boundaries without invalid factorials.
Show solution and calculation
For n=0 and n=1, p=0.
For n=257>256, p=1 by the pigeonhole principle.
Error analysis · Application
For n=20, M=256, someone reports 190/256 as exact probability.
Show hint
The probability of a union of overlapping pair events is not simply their sum. Use the pair sum only as an upper bound.
Learning goal: Distinguish expected pair count from event probability.
Show solution and calculation
190/256 is an upper bound rather than the exact event probability.
The product gives about 0.533167 rather than 0.742188.
Transfer · Application
Two independent uniform 128-bit outputs: what is collision probability?
Show hint
There is exactly one pair.
Learning goal: Represent tiny probabilities stably.
Show solution and calculation
p=1/2128≈2.938735877·10−39.
Directly subtracting nearly equal floating-point numbers is unsuitable here.
Interpret · Foundation
The same file is entered twice into a deterministic hash. Does the repeated hash prove a random collision of distinct files?
Show hint
Check what the model treats as independent draws.
Learning goal: Distinguish repeated input from random collision.
Show solution and calculation
No.
Identical inputs must give the same deterministic hash.
The model concerns independent uniform outputs for distinct considered items under the stated random assumption.
Check your understanding with the formula’s reference test.
8 test questions · English materials
Already have an account? Sign in for the testAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Sources for this explanation
Quanta · Updated November 21, 2026
Editorial responsibility: Quanta Study editorial team
Review scope
This explanation, 2 worked examples and 5 exercises are available in German and English. Structure, source references and mathematical notation undergo automated checks. Calculations, model assumptions and both language versions receive a separate AI review.
An independent, named human subject review has not yet been documented. Our exercise numbers are worked examples, rather than measurements published by the cited sources.
Editorial responsibility, sources and methodsChange history
- Separated exact product, approximation and pair bound; added four learning steps, five task titles and precise guidance on pair events.
- Authored a distinct DE/EN article with model limits, two worked examples and five varied exercises.
Cite this reference page
Quanta. Hash collision probability (birthday bound). Updated November 21, 2026. https://quanta-study.de/en/formula-sheet/hashkollision-geburtstagswahrscheinlichkeit
When citing a specific scientific statement, also cite the specialist source linked to that statement.