Can a UUID v4 ever collide?
Yes. With a good random source, even among one trillion UUIDs, the chance of an accidental match is about one in 11 trillion.
Here's why repeats are possible, and what that means for the IDs you use.
What part of a UUID v4 is random?
A UUID is a label for something in an app, such as a customer record or a request. Think of a coat-check ticket: its printed marks tell staff how to read it, while the changing number tells them which coat is yours. Version 4 makes the changing part at random, so separate computers can make labels without sharing a counter.
A UUID v4 has 122 random bits—yes-or-no choices—and 6 bits that mark its format. Here's the recorded UUID 80939bb4-d9b8-40da-9f73-21578b3522c2, with those markers picked out.
Those familiar hyphens help you read the label. They don't add randomness, and the format markers don't describe the customer, request, or device that made it.
Why can two UUID v4s match?
A random choice can repeat. The generator doesn't cross an ID off a shared list after it's used. Two computers can therefore pick the same value, even though neither has seen what the other made. That exact repeat is called a collision.
Each new label could match any label you've already made. Connecting every possible pair shows why the chance grows as the group grows.
That's the idea behind the birthday puzzle: you're looking for any two people with the same birthday, not someone with your particular birthday. With UUIDs, the pool of choices is vastly larger. A collision can happen before you've used every choice; filling the pool isn't the condition for a repeat.
How small is the UUID v4 collision risk?
Assume each UUID is a fresh choice, independent of the others, with every possible value equally likely. These calculated odds are for any matching pair in the whole group.
Even with one trillion UUIDs, the chance of any match is about one in 11 trillion. That's why version 4 works well when different parts of an app need to make IDs without coordinating each choice.
These odds come from a probability calculation. How we reviewed separates that calculation from the recorded generator check.
What should an app do with UUID v4 IDs?
Use a cryptographic random source to make UUIDs. FluffyBench's UUID generator uses Web Crypto, the browser's built-in source for security work.
If your records must have different IDs, enforce that rule on every save, for example with a database unique constraint. A separate check before saving can miss two requests arriving together. The constraint prevents them from both storing the same ID; handling an actual random collision should be rare.
Does knowing a UUID give someone access?
An ID names a record; it doesn't grant permission to open it. A UUID can appear in a link, a log, or a message, so the app needs its own access check.
Doing it in FluffyBench
Here's how to make five IDs with FluffyBench's UUID generator and take the list with you.
-
Step 1. Choose five IDs and the spelling your app expects. - How many sets the batch size; enter 5.
- Letters changes case; leave lowercase selected.
- Keep the hyphens adds separators; leave it checked.
-
-
Step 2. Press Generate 5 new UUIDs to make a fresh batch. - Generate makes five fresh IDs.
-
-
Step 3. Check that the result contains five IDs in the spelling you chose. - Each row is one new UUID.
-
-
Step 4. Copy the list, or save it as uuids.txt. - 5 UUIDs confirms the result count.
- Copy all puts one ID per line on your clipboard.
- Download .txt saves one ID per line.
-
Need FluffyBench's UUID generator to make IDs for your app?
Make fresh version 4 IDs and copy the list into your app.