Formula: Hash Collision Paradox Systems Engineering Formula
- hashEntropyBitsB: Hash Entropy Bits B (bits)
- generatedIdsCountN: Generated Ids Count N (IDs)
Evaluate collision risk for 32-bit, 64-bit, or custom short-link random IDs.
No. The headline rounds to two decimal places, so very small probabilities display as 0. The 96-bit preset, with a hundred million IDs, shows 0% but its odds line reads 1 in 15,845,632,661,300, a tiny chance that is not zero. Any random ID scheme has some nonzero chance of a duplicate, which is why a uniqueness constraint in storage is still good practice.
Multiply the number of characters by the base 2 logarithm of the alphabet size. For an alphabet of 62 letters and digits, each character carries about 5.95 bits. For hex, each character is exactly 4 bits. Only count characters chosen at random; fixed prefixes, separators or check digits add length but no entropy to the ID.
Setting the approximate probability to one half and solving for n gives n equal to the square root of 2 times ln 2 times 2^b. The square root of 2 ln 2 is about 1.1774, and the square root of 2^b is 2^(b/2). So for 64 bits the threshold is 1.1774 times 2^32, about 5.06 billion, which is the 5,056,937,541 the page shows.
It is very close in most practical cases. The exact birthday formula multiplies many terms, and the exponential form is an excellent approximation when the number of IDs is much smaller than the number of possible values. For tiny spaces and counts the two drift slightly, but for the 64-bit and larger IDs this page is built for, the difference is negligible.
Yes. The n in the formula is the total number of IDs that share a namespace, across every server, every region and the system's whole history. Ten servers each generating a hundred million IDs means n is a billion, and at 64 bits the page shows 2.67% rather than 0.0271%. Enter the lifetime total, not one machine's share.
Count every ID that could still be compared against a new one. If expired IDs are removed from the namespace and can safely be reissued, they no longer matter. If they live on in logs, backups, links or caches where a duplicate could cause trouble, they still count. When in doubt, use the total ever issued, which gives the more cautious figure.
Not directly. The page answers whether any two items share a full ID, which is the birthday question. Hash table design usually cares about how many items land in each bucket and how long chains get, which needs different formulas. The calculator is aimed at identifiers and digests where any duplicate at all is the failure you want to avoid.
It shows how quickly a short ID fails. At 38 bits, the 1% threshold is 74,330.65 IDs and the 50% point is 617,302 IDs, so a hundred million IDs is far past certainty. A 38-bit ID is about the size of a short link code, and the preset illustrates why such codes need a uniqueness check on creation rather than relying on luck.
Not the answer, but whether you can trust it. The formula assumes every ID is drawn uniformly and independently. A good cryptographic generator meets that assumption. A poor or badly seeded generator can repeat values far sooner than the page predicts, so the figure is only meaningful if your generator is sound.
The cheapest fix is usually more random bits, since each extra 2 bits doubles the count at which collisions become likely. You can also enforce uniqueness in storage and retry on a clash, or shorten the lifetime of the namespace. Rerun the page with the new bit length and your expected lifetime count to see whether the risk is acceptable. The odds line is often the clearest way to present the result to others.
The default case generates 100,000,000 random identifiers, each 64 bits long. The page reports a collision probability of 0.03% in the headline, and the interpretation sentence gives the more precise figure of 0.0271%. That is the chance that at least two of those hundred million IDs are identical.
Two thresholds sit underneath. The 50% birthday bound for 64 bits is 5,056,937,541 IDs, about five billion, and the 1% threshold is 608,916,706.85 IDs, roughly six hundred million. The last line, 16 hex chars, tells you how long the ID would be written in hexadecimal.
Read together, the lines say that a hundred million 64-bit IDs is comfortably safe for most purposes, but not by the huge margin people often assume. You are about a sixth of the way to the 1% point. Grow the system tenfold and the picture changes quickly.
The approximation the page uses is p ≈ 1 − exp(−n² / (2 × 2^b)), which is the same as dividing n squared by 2 to the power b plus 1. You can verify the default on paper.
Here n is 10^8, so n squared is 10^16. For 64 bits, 2^65 is about 3.69 × 10^19. Dividing gives 2.71 × 10^−4. When that exponent is small, 1 minus e to the minus x is almost exactly x, so the probability is about 0.000271, or 0.0271%. That matches the interpretation line.
The 50% threshold comes from setting p to one half and solving for n, which gives the square root of 2 × ln 2 × 2^b. That is the same as 1.1774 times 2 to the power b over 2. For 64 bits, 2^32 is about 4.29 billion, and multiplying by 1.1774 gives roughly 5.06 billion, the figure on the page.
The 1% threshold works the same way with ln of 1 over 0.99 in place of ln 2.
The number of IDs enters the formula squared. For small probabilities, doubling n roughly quadruples the chance of a collision, and multiplying n by ten multiplies the chance by about a hundred.
Try it on the page. Keep 64 bits and raise the count from a hundred million to a billion. The probability jumps from 0.0271% to 2.67%. That is not quite a hundredfold increase, because once the exponent is no longer tiny the exponential starts to bend the curve, but it is close.
This is the core of the birthday paradox. Each new ID has to avoid every ID already issued, so the number of pairs that could collide grows with the square of the count. With 23 people in a room there are already more than two hundred and fifty possible pairs, which is why shared birthdays turn up so much sooner than intuition suggests.
For capacity planning, this means the right question is not how many IDs you have now but how many you will have accumulated over the system's whole life.
The presets compare three ID sizes at the same hundred million IDs. At 38 bits the collision probability rounds to 100%, and the 50% point is only 617,302 IDs. At 64 bits it is 0.0271%. At 96 bits the headline shows 0%, and the 50% point is 331,411,458,666,436 IDs, in the hundreds of trillions.
The pattern is that each extra 2 bits doubles the 50% threshold, because the threshold grows with 2 to the power b over 2. Going from 64 to 96 bits adds 32 bits and multiplies the threshold by 2 to the 16th power, which takes it from about five billion into the hundreds of trillions.
The 96-bit result of 0% is a display rounding, not a true zero. The real figure is a tiny fraction of a millionth of a percent. The headline rounds to two decimal places, so anything that small shows as 0.
Bits are cheap in storage terms. Moving from 64 to 96 bits adds only eight hex characters to each ID, as the hex line shows: 16 against 24.
A 32-bit random ID looks roomy because it can take over four billion values. Run it through the page and the birthday effect shows why that is misleading. With 32 bits the 50% threshold is only about seventy-seven thousand IDs, and the 1% threshold is a little over nine thousand.
Enter 32 bits and a count of about seventy-seven thousand and the page shows 49.85%, essentially a coin toss. Raise the count to a hundred thousand and it climbs to 68.78%. A small internal tool, a session table or a batch of order references can reach those numbers within weeks.
Compare that with the default 64 bits, where the 50% bound is 5,056,937,541 IDs. Doubling the bit length did not double the safe count, it squared it. That is the most useful single lesson the page teaches: the safe number of IDs grows with the square root of the number of possible values, not with the number of values itself.
If an existing system uses 32-bit random keys, the fix is rarely complicated. Widen the column, or add a uniqueness check and retry on conflict.
The bits input is the number of random bits, which is often less than the length of the ID suggests. A version 4 UUID fixes six of its bits for the version and variant, so its random portion is six bits shorter than its full length. Time-ordered ID schemes devote many of their bits to a timestamp, leaving a smaller random part.
Short link and token systems need the same care. An ID written in a 62-character alphabet carries a little under 6 bits per character, not 8. A hex string carries exactly 4 bits per character, which is the conversion the Hexadecimal Characters line uses.
That line rounds up to a whole number of characters, because you cannot write half a hex digit. At 38 bits it shows 10 hex chars, which can actually hold 40 bits. The extra two bits are free capacity, so if you are designing a hex ID you might as well generate all 40.
If part of an ID is derived from a counter, machine number or user input, those bits are not random and should not be counted. Overstating b makes every number on the page look safer than reality.
The same arithmetic applies to hash functions when the inputs are effectively random and nobody is trying to force a collision. Truncating a long digest to 64 bits for a cache key or a deduplication index gives exactly the default case: about a 0.0271% chance of at least one clash across a hundred million distinct items.
It does not apply when someone is deliberately searching for a collision. An attacker who can generate many candidates is exploiting the same birthday effect, but against your chosen bit length, and a 64-bit digest is not considered strong against that. The calculator's figures describe accidental collisions only.
It also assumes the generator is good. A weak random number generator, a seed reused across processes, or a container image that starts every instance with the same state can produce duplicates far sooner than the formula predicts. The maths is only as good as the randomness feeding it.
The 1% line is often the most practical one for design work. For 64 bits it is 608,916,706.85 IDs. For 38 bits it is 74,330.65 IDs, and for 96 bits it is 39,905,965,300,100 IDs. A system that will issue fewer IDs than the 1% figure over its whole lifetime has at most about a one in a hundred chance of any collision.
Many teams want far lower risk than 1%, particularly where a collision would merge two customers' records or expose one user's data to another. In that case, keep the expected lifetime count well below the 1% threshold, or add enough bits that it is far out of reach.
It also helps to decide what happens on a collision. If the database enforces uniqueness and the application can retry with a fresh ID, a small collision probability costs a retry. If a duplicate silently overwrites data, even a tiny probability may be too much, and the safer fix is a uniqueness check rather than more arithmetic.
Alongside the percentage, the page shows Odds of a Collision (1 in N). For the default it reads 3,689.85, meaning roughly a one in three thousand seven hundred chance of any duplicate among a hundred million 64-bit IDs. At 96 bits it reads 15,845,632,661,300, and at 38 bits it reads 1, a near certainty. Many people find odds easier to judge than a small percentage.
The odds line is especially useful when the headline rounds. The percentage is shown to two decimal places, so the default appears as 0.03% and the 96-bit case as 0%, while the odds line keeps the real scale visible.
The inputs are checked. Bits must be a whole number from 8 up to several hundred, and the ID count must be a whole number of at least 2, since a single ID cannot collide with anything. Anything outside those limits shows an error instead of a result. For an alphabet that does not map to whole bits, round the entropy down to be safe.