← Back to section · Foundations of Cryptography
Probability and the Birthday Bound: Cryptography's Counter-Intuitive Square Root
Among just 23 people, the chance that two share a birthday exceeds one half. This birthday paradox is a yardstick of cryptographic security: an n-bit hash offers only about n/2 bits of collision resistance. The article derives the bound, gives the approximation, and shows its use for hashes, randomness and password parameters.
Cryptographic security parameters are quoted in bits: 128 bits, 256 bits. But these numbers are not worth the same everywhere, and the largest discount comes from one probabilistic law — the birthday bound. It originates in a famous puzzle: how many people must be in a room before the probability that two share a birthday exceeds one half? Intuition says one or two hundred; the correct answer is 23. This article derives the bound and shows how it fixes the parameters of hash functions, random values and session identifiers.
The birthday problem: the number of pairs quietly explodes
With 365 days in a year, add students one by one and demand all birthdays be distinct. When the k-th student arrives, they must avoid the previous k − 1 birthdays, with probability (365 − k + 1)/365. The probability that everyone is distinct is the product of these factors. The key is how things grow: among n people there are n(n − 1)/2 pairs, and every pair is a potential collision point. At n = 23 the pair count reaches 253, and the probability of at least one shared birthday rises to about 50.7%; at n = 30 it is about 70.6%; at n = 50, about 97%. Collisions arrive far earlier than intuition suggests, because the number of pairs grows with the square of n.
The general form: the √N rule
Replacing 365 by a general N (the number of equally likely values), one can derive the approximation: after k uniform draws, the probability of no collision is about exp(−k²/2N). Setting this equal to 1/2 gives k ≈ 1.18√N. In other words, once the number of draws reaches the order of the square root of the space, collisions pass from accident to routine. This square-root rule is one of the most used estimation tools in cryptography: any argument that “the space is too large for a repeat to occur” must first pass the square-root test — a space of 10^18 has a square root of only 10^9, well within reach of modern computation.
For hash functions: collision resistance is halved
A hash function maps arbitrary inputs to n-bit outputs, a space of N = 2^n. An attacker seeking any colliding pair — any two distinct inputs with the same output — is performing birthday sampling: after about 2^(n/2) trials the success probability reaches the one-half range. Collision resistance is therefore only n/2 bits: MD5’s 128-bit output yields only about 64 bits (in practice less, due to structural weaknesses), SHA-1’s 160 bits about 80 bits, and SHA-256 about 128 bits — the origin of the slogan “a 256-bit hash gives 128-bit security”.
Note the asymmetry, however: if the target is one given hash value and the attacker wants its preimage, the birthday bound does not help, and about 2^n trials are still needed. The three security goals of a hash — collision resistance, second-preimage resistance, preimage resistance — carry strengths of roughly n/2, n and n bits respectively. When reading a parameter table, first asking which goal is meant is basic literacy.
One detail is often raised: the naive birthday attack must store all outputs tried so far for comparison, and 2^(n/2) of storage is as expensive as the computation — is the bound just a theoretical trick? It is not. Pollard’s rho method and its parallel version (the van Oorschot–Wiener parallel collision search) perform the same collision search with very little memory and near-linear parallel speed-up. The birthday bound therefore states an actually achievable attack cost, not an unattainable lower bound. Computing collision resistance at n/2 is both conservative and correct.
Random values, passwords and sessions: the square root is everywhere
The birthday bound also governs many seemingly unrelated parameters. Randomly generated session identifiers, unique file IDs, random nonces: with only 64 bits, after about 2^32 (roughly 4.3 billion) values a repeat becomes as likely as not — not an astronomical count for a large system, and a repeat can mean session conflicts or nonce reuse, the latter being catastrophic in some encryption modes. This is why modern systems favour 128-bit random identifiers: after the square root, a margin of 2^64 remains. Password and key spaces obey the same logic: any design that “combines random values” must be evaluated at the square-root scale.
The most familiar everyday example is the UUID: a version-4 UUID carries 122 random bits, so by the birthday bound roughly 2^61 values must be generated before a collision becomes more likely than not — far beyond any real system’s total output, hence safe to use in practice; but truncate a UUID to 64 bits and the conclusion instantly reverses. Calibrating intuition at hash scale: with an output space of 2^128, the threshold is about 2×10^19 trials — even pooling the world’s computing power at 10^18 trials per second, it would take on the order of centuries. That is the quantitative account behind “128-bit collision resistance” being considered enough in engineering.
Collisions in the real world: from block ciphers to hashes
The birthday bound is not paper mathematics. When a 64-bit block cipher (such as 3DES or Blowfish) encrypts large amounts of data under one key in CBC mode, collisions between blocks leak XOR relations between plaintexts — the Sweet32 attack, published in 2016, applied the birthday bound exactly here: after about 2^32 blocks (roughly 32 GB of data) collisions become likely, a generation of legacy VPN and HTTPS configurations was condemned, and 64-bit block ciphers accelerated their exit. The hash-side lesson is even more famous: the practical collision attacks on MD5 and SHA-1 certainly exploited structural weaknesses and ran far faster than the birthday bound, but even pretending their structures were perfect, the bound had already compressed 128-bit MD5 to about 64 bits and 160-bit SHA-1 to about 80 bits — under continuing growth of computing power, both were only a matter of time. Parameter selection must always read two accounts at once — the discount from structural attacks and the discount from the birthday bound — and take the harsher one.
A caveat: the uniformity assumption
One condition of applicability deserves a final warning: all the calculations above assume the draws are uniformly random. If the random source is biased — some values occurring more often than others — collisions arrive earlier than the birthday bound predicts, because frequent values collide with each other more readily. Defective random number generators and biased identifier-generation algorithms in real systems quietly erode the safety margin the bound provides. The square-root account in parameter tables therefore presupposes that the randomness itself is sound; the quality of the random source (see the Shannon entropy article in this section) and the birthday bound are two sides of the same coin.
Summary
The birthday bound teaches one sentence: for probabilities of “any two being equal”, compute with the square root; for “equal to a specified target”, compute with the whole space. Half of the apparently generous bits in parameter tables are often reserved for exactly this square root. Next time you see “256 bits”, ask first: which kind of collision is it defending against?
Tags: ProbabilityBirthday AttackHash Collisions