UUID & NanoID Collision Probability Calculator

Last updated

Estimates the chance that randomly generated IDs collide with the birthday bound p = 1 − e^(−n(n−1)/2D), where n counts the IDs and D the possible values: 2^122 for UUIDv4, 2^126 for a 21-character NanoID and 16^k for a k-digit Git hash. UUIDv7 and ULID values can collide only within one millisecond, so D becomes 2^74 or 2^80 per millisecond. It also solves for when the risk reaches 1 in a million, 1% and 50%.

Per
Period unit
Collision chance –
Random bits per ID –
IDs counted –
When each risk level is reached
Alternatives at the same load

Pick an ID format, a creation rate and a period, and the calculator gives the chance that any two IDs ever match, when that chance reaches 1 in a billion, 1 in a million, 1% and 50%, and how UUIDv4, UUIDv7, ULID and a 21-character NanoID compare at the same load. For Git it takes the object count instead and shows how often a short hash is ambiguous at each length. With the defaults, 1,000 UUIDv4s a second for a year, you make 31.6 billion IDs and the chance of a duplicate is 1 in 10.7 quadrillion.

The birthday paradox behind every ID

Any two matching IDs make a collision, which is the birthday problem: with N people and c possible birthdays, the chance that nobody shares one is the product of (1 − i/c) for i from 1 to N − 1. In their 1989 paper "Methods for Studying Coincidences", the statisticians Persi Diaconis and Frederick Mosteller call that formula "easy to calculate, but hard to think about" and give the approximation this page builds on: when c is large and N is small compared with c2/3, the chance of no match is about e−N²/2c. Even odds then need N ≈ 1.2√c, or 23 people for 365 birthdays. As far as they knew, Richard von Mises made the earliest mention of the problem, in 1939.

The surprise comes from counting pairs, not people. Twenty-three people form 253 pairs, each sharing a birthday 1 time in 365, so about 0.69 matching pairs are already expected. Diaconis and Mosteller open their paper with a line from R. A. Fisher that suits any ID scheme: "the 'one chance in a million' will undoubtedly occur, with no less and no more than its appropriate frequency."

From DCE to RFC 9562

RFC 4122, published in July 2005, traces the 128-bit UUID to the Apollo Network Computing System, then to the Open Software Foundation's Distributed Computing Environment, and then to Microsoft Windows. Its version 4 is the random one: set 6 bits to mark the version and variant, and fill the other 122 with random or pseudo-random values.

RFC 9562 replaced it in May 2024. Its authors note that UUIDs not ordered by time, such as version 4, have poor database-index locality, and they analysed 16 existing ID schemes, ULID first among them, before adding version 7. A UUIDv7 starts with a 48-bit Unix timestamp in milliseconds that the RFC says is valid until the year 10889 AD, and fills the remaining 74 bits with random data.

To keep v7 IDs in order within one millisecond, the RFC offers a counter of 12 to 42 bits, randomly initialised at each new timestamp tick (Method 1), a randomly seeded value incremented in place (Method 2), or up to 12 bits of extra clock precision, 4,096 steps per millisecond (Method 3). It warns that more generating nodes make a collision likelier, and asks for a cryptographically secure random generator reseeded when a process forks.

ULID, NanoID and Git's short hashes

ULID has the same 48-bit millisecond timestamp but 80 random bits, written as 26 Crockford base32 characters. Its specification puts that at 1.21e+24 unique values per millisecond, lasting until the year 10889. In monotonic mode a generator adds 1 to the random part when the millisecond repeats, and fails if that part overflows.

Andrey Sitnik's Nano ID draws from a 64-symbol alphabet of letters, digits, underscore and hyphen, so its IDs shrink from the 36 symbols of a written UUID to 21. Its README counts 126 random bits in Nano ID against 122 in UUID, and says a one-in-a-billion chance of duplication needs 103 trillion version 4 UUIDs, the same figure this calculator gives.

Git names each object by a hash written as 40 hexadecimal digits (64 in SHA-256 repositories) and accepts any unique prefix of it. The default prefix had long been 7 digits. In September 2016 Linus Torvalds wrote a change, released in Git 2.11 on 29 November 2016, because short names recorded in old log messages were no longer unique: the Linux kernel needed 11 to 12 hex digits and Git itself 10. Git now takes its approximate count of packed objects, finds its bit length, halves it rounding up and uses that many digits, never fewer than 7. The kernel's patch guide asks for at least the first twelve characters of a commit ID. To match Git's default, enter the in-pack figure from git count-objects -v; to count every object, add its loose count.

How the calculation works

For n IDs drawn from D equally likely values, the expected number of matching pairs is n(n − 1)/2D, and the chance of at least one match is:

p = 1 − e−n(n − 1) / 2D, where D = AL

Here A is the alphabet size and L the length, so D is 2122 for UUIDv4, 6421 = 2126 for NanoID and 16k for a k-digit Git prefix. The exponential slightly understates the risk, so for spaces of up to 232 values the calculator multiplies out the exact product instead: with a million possible values, 2 IDs are already exactly 1 in a million, where the formula needs 3.

UUIDv7 and ULID values can only clash with others made in the same millisecond. At r IDs a second, each millisecond holds λ = r/1000 of them on average. If arrivals are random, the expected matching pairs in one millisecond are λ²/2D, so over T milliseconds:

p = 1 − e−Tλ2 / 2D

with D = 274 for UUIDv7 and 280 for ULID. When a risk level is reached inside the first millisecond, the calculator counts the pairs among the IDs made so far instead, and no level is reached before the second ID. The "Prefixed with a millisecond timestamp" box applies the same model to a custom ID.

Times come from solving these formulas backwards, with a 365.25-day year. For Git the object count is n, and a second column gives the chance that one particular hash shares its prefix with any of the other n − 1: 1 − (1 − 16−k)n − 1.

Worked example

At the defaults, 31.6 billion UUIDv4s carry a 1 in 10.7 quadrillion chance of a duplicate. The risk reaches 1 in a billion after 3,270 years, by which time you would have made 103 trillion IDs, then 1 in a million after 103,000 years, 1% after 10.4 million years and 50% after 86 million years.

In the comparison table a 21-character NanoID does best, at 1 in 171 quadrillion. UUIDv7 comes out at 1 in 1.2 trillion, about 8,919 times UUIDv4's risk, and ULID at 1 in 76.6 trillion. Because v7's risk grows with time rather than with the square of the total, the two even out only after 248 milliseconds, about 8,919 years: the whole span of the 48-bit clock that ends in 10889. Over that span at 1,000 IDs a second, UUIDv7 and UUIDv4 both reach 1 in 134 million and ULID 1 in 8.59 billion, so neither time-ordered format ever gets to 1 in a million, and the table says "clock ends first". UUIDv7 does pass 1 in a billion, after 1,200 years.

Short custom IDs show why length matters. Eight characters from a 62-symbol alphabet carry 47.6 bits; at 1,000 a second they pass 1 in a million after 20.9 seconds and 50% after 4.83 hours. An alphabet of 365 with length 1 replays the birthday problem: 23 IDs give 50.73%, and 22 give 47.57%.

For Git with the default 1,000,000 objects, at 7 digits some pair almost certainly shares a prefix, at more than 99.99%, but the chance that a given hash is ambiguous is only 0.372%. Git's own default for that count is 10 digits, where a shared prefix somewhere has a 36.54% chance and a given hash is ambiguous 1 time in 1.1 million. At the kernel's 12 digits the shared-prefix chance falls to 0.177%.

Reading the result

The figures assume good random bits and IDs that arrive at random times. Forked processes sharing a random state, clocks that step backwards and bursts inside one millisecond all make collisions far likelier. A single monotonic generator, ULID's or an RFC 9562 counter, cannot repeat itself within a millisecond, so for one generator the page gives an upper bound. Method 3's clock bits act like random bits only if the clock ticks 4,096 times per millisecond, about every 244 nanoseconds; a microsecond clock fills only about 10 of the 12. A v7 counter that starts at zero each millisecond leaves fewer random bits, so model it as a custom time-prefixed ID.

A Git prefix collision corrupts nothing. Git prints a longer prefix whenever a short one would be ambiguous, so the risk is an old short hash in a commit message that no longer names a single object.

Frequently asked questions

How likely is a UUIDv4 collision?

Generating 1,000 UUIDv4s a second for a year makes 31.6 billion IDs, and the chance that any two match is about 1 in 10.7 quadrillion. A 50% chance needs about 2.71 quintillion IDs: 86 million years at that rate, or 86 years at a billion IDs a second.

Is UUIDv7 more likely to collide than UUIDv4?

Yes, when all 74 bits after the timestamp are random and the IDs come from independent generators. Only IDs made in the same millisecond can clash, so the risk grows with time instead of with the square of the total. At 1,000 IDs a second for a year UUIDv7 gives 1 in 1.2 trillion against UUIDv4's 1 in 10.7 quadrillion. The two even out only after 2^48 milliseconds, about 8,919 years, which is the whole span of the 48-bit clock.

How long should a NanoID be?

The default 21 characters from a 64-symbol alphabet carry 126 bits, so 1,000 IDs a second for a year leaves 1 in 171 quadrillion. Each character removed costs 6 bits. At 10 characters (60 bits) the same rate reaches 1 in a million after 25.3 minutes and 50% after 14.6 days.

Why does Git print longer short hashes in big repositories?

Since Git 2.11 in 2016, Git takes the bit length of its approximate count of packed objects, halves it rounding up, and uses that many hex digits, never fewer than 7. A repository of 1 million objects gets 10 digits, where the chance that some pair shares a prefix is 36.54%. Git still prints a longer, unique prefix when a shorter one would be ambiguous.

What is the birthday paradox?

23 people give a 50.73% chance of a shared birthday: they form 253 pairs, and each pair matches 1 time in 365. The number of pairs grows with the square of the crowd, so a 50% chance arrives near 1.2 times the square root of the number of possible values.

Do monotonic ULIDs or UUIDv7 counters prevent collisions?

Only within one generator, which increments rather than redrawing inside a millisecond. Separate processes can still collide, and this calculator treats every ID as independently random, which makes its figure an upper bound for a single generator.

Sources

  1. RFC 9562: Universally Unique IDentifiers (UUIDs), Internet Engineering Task Force, 2024
  2. RFC 4122: A Universally Unique IDentifier (UUID) URN Namespace, Internet Engineering Task Force, 2005
  3. Methods for Studying Coincidences (Persi Diaconis and Frederick Mosteller), Journal of the American Statistical Association, 1989
  4. Universally Unique Lexicographically Sortable Identifier (ULID) specification, ulid on GitHub
  5. Nano ID, Andrey Sitnik on GitHub
  6. Git 2.11.0 release notes, The Git project, 2016
  7. abbrev: auto size the default abbreviation (Linus Torvalds), The Git project, 2016
  8. find_unique_abbrev: move logic out of get_short_sha1() (Jeff King), The Git project, 2016
  9. odb.c: odb_find_abbrev_len, Git 2.56.0 source, The Git project, 2026
  10. Git hash function transition, The Git project
  11. git-config: core.abbrev, Git documentation
  12. Submitting patches: the essential guide to getting your code into the kernel, The Linux kernel documentation