UUID v4 structure: 122 random bits and collision odds

Contents
If you've ever looked at a string like f47ac10b-58cc-4372-a567-0e02b2c3d479 and wondered, "Can this really never collide?" — this post is for you. Here's the short answer: in a UUID v4, 122 of the 128 bits are random, and the other 6 bits are a fixed marker that says "I'm a v4."
So "no collisions" isn't a matter of faith — it's arithmetic. Once you know how the slots are laid out, you can spot a v4 by eye and work out the collision odds yourself.
Summary ① 36 characters = 32 hex digits + 4 hyphens. It's 128 bits (16 bytes) cut into 8-4-4-4-12. ② The first character of the third group is always
4(the version), and the first character of the fourth group is one of8,9,a, orb(the variant). ③ Those 122 remaining bits are random, so there are 2¹²² possible values — about 5.3 × 10³⁶.
Why the 8-4-4-4-12 Split?
A UUID is a 128-bit value. Written in hex, each of its 16 bytes becomes two characters, so you get 32 characters. Then 4 hyphens are inserted to break it into five groups.
That's why a UUID string is always 36 characters long. If the length isn't 36, you can rule it out as non-standard on the spot.
Where the groups split is fixed by the spec. RFC 9562, published in May 2024, is the current standard, and it replaces the long-used RFC 4122.
| Group | Characters | Position among the 32 hex digits (hyphens removed) | Special slot |
|---|---|---|---|
| 1st | 8 | 1–8 | — |
| 2nd | 4 | 9–12 | — |
| 3rd | 4 | 13–16 | first character = version |
| 4th | 4 | 17–20 | first character = variant |
| 5th | 12 | 21–32 | — |
RFC 9562 defines the version field as the top 4 bits of the sixth octet (bits 48–51 overall). That's the first character of the third group.
In v4 those 4 bits are fixed at 0100, so they always show up as 4. In the example earlier, ...-4372-..., that leading 4 is exactly this.
The variant field is the top 2 bits of the eighth octet — the first character of the fourth group. Because those 2 bits are fixed at 10, that one character can only be 8, 9, a, or b.
So a v4 always looks like this. The y slot can only be 8, 9, a, or b.
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
↑ ↑
version 4 variant (8/9/a/b)
How to Check One Yourself, No Tools Needed
There are three ways to check whether a value you received is really a v4.
1. Eyeball it. Just check that splitting on hyphens gives 8-4-4-4-12, that the first character of the third group is 4, and that the first character of the fourth group is one of 8, 9, a, b.
2. Generate one right in your browser. Type the following into the console in your developer tools (usually F12) and you'll get a v4.
crypto.randomUUID()
// → "36b8f84d-df4e-4d49-b662-bcde71a8764f"
This function builds a v4 from cryptographically secure random numbers. It only works in a secure context (HTTPS or localhost), though, so on a page served over http:// you may find the function simply isn't there.
3. Validate the format with a regex. This checks length, separator positions, version, and variant all at once.
const isV4 = (s) =>
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(s);
isV4("f47ac10b-58cc-4372-a567-0e02b2c3d479") // true
isV4("f47ac10b-58cc-1372-a567-0e02b2c3d479") // false (v1)
This is where it gets tedious. The console gives you one at a time, and if you need several — or need them with the hyphens stripped or in uppercase — you have to edit the code and run it again each time.
Check it with our tool. Enter a count and press Generate to get the whole list at once, along with Remove hyphens and Uppercase options and a Copy all button.
It runs right in your browser with no install and no sign-up, and the UUIDs you create are never sent to a server.

What 122 Bits Actually Means: Doing the Collision Math Yourself
Take 128 bits, subtract the 4 version bits and the 2 variant bits, and 122 bits remain. RFC 9562 defines v4 as random_a (48 bits), random_b (12 bits), and random_c (62 bits), and states that the combined 122 bits are random.
So the number of values a v4 can hold is 2¹²². Written out, that's 5,316,911,983,139,663,491,615,228,241,121,378,304 — roughly 5.3 × 10³⁶.
That's hard to picture, so here's another way to put it: it's bigger than a trillion (10¹²) multiplied by itself three times.
Collision Odds Come From the Birthday Problem
What matters isn't the chance of matching one specific value — it's the chance that the ones you generate collide with each other. That's the same math as the birthday problem, and the approximation looks like this.
p ≈ n² ÷ (2 × N) — where n is how many you generate and N is the number of possible values (2¹²²)
Plug in some numbers and you get the following. These are values you can verify by hand.
| Number of UUIDs generated | Chance of at least one collision (approximate) |
|---|---|
| 1 billion | About 9.4 × 10⁻²⁰ (less than 1 in 10 quintillion) |
| About 103 trillion | About 1 in a billion |
This approximation only holds where the probability is very small. The point where the probability reaches one half comes from the other birthday-problem formula: n ≈ 1.18 × √N.
Put N = 2¹²² into that and you get about 2.7 × 10¹⁸, or 2.7 quintillion. That's a different order of magnitude from the number of identifiers any single service generates.
The Real Risk Isn't the Odds: It's Your Random Source
The calculation above only holds if those 122 bits are uniformly random. If the randomness is biased or predictable, the real number of possibilities shrinks and the math stops meaning anything.
That's why RFC 9562 recommends a cryptographically secure random number generator (CSPRNG). The browser's crypto.randomUUID() and crypto.getRandomValues() fit the bill.
A UUID padded out with Math.random(), by contrast, is a v4 in format only — none of those odds are guaranteed. The spec itself notes that guaranteeing global uniqueness without a shared body of knowledge is impossible.
Common Sticking Points
| Situation | The facts |
|---|---|
| Storing it without hyphens as 32 characters | The positions are fixed, so you can always restore the 8-4-4-4-12 form |
| Writing it in uppercase | RFC 9562's ABNF allows uppercase, lowercase, and mixed case |
| Wrapping it in curly braces | That's a GUID display convention, not a string format from the RFC |
| A value of all zeros | That's the Nil UUID, and it isn't a v4 (the version and variant slots are zeros too) |
| Sorting them to work out creation order | A v4 contains no time information at all, so this is impossible |
The most common accident is letter case. Per the spec both forms are valid and represent the same UUID, but if your database or code compares them as plain strings, they get treated as different values. It's safer to normalize to one case when you store them.
The other one is database indexes. RFC 9562 points out directly that non-time-ordered UUIDs like v4 have poor database index locality, because values created one after another are scattered across the index, so inserts land at random positions.
v7 is what RFC 9562 newly defines to target this problem. Its leading part is a millisecond timestamp from the Unix epoch, so values sort in creation order, and the remaining slots are filled randomly. If you don't need ordering, v4 is enough.
Summary
- A UUID is 128 bits: 32 hex characters plus 4 hyphens for 36 characters, split as 8-4-4-4-12.
- The first character of the third chunk is the version. For v4 it is always
4. - The first character of the fourth chunk is the variant. Its top 2 bits are fixed at
10, so it can only be8,9,a, orb. - The remaining 122 bits are random, which gives 2 to the 122nd power possible values (about 5.3 × 10³⁶).
- Even if you generate 1 billion of them, the chance of a collision is less than 1 in ten quintillion, and you would need about 2.71 quintillion to reach 50%.
- These odds only hold if the random source is cryptographically secure. Implementations based on
Math.random()do not qualify.
It runs right in your browser with no install and no sign-up, and the UUIDs you create are never sent to a server.
Frequently asked questions
Are UUID v4 values guaranteed never to collide?
No, and the spec doesn't claim that either. RFC 9562 states that guaranteeing global uniqueness without a shared knowledge system is impossible. Instead, the 122 random bits push the collision probability down to a level that is negligible in practice. Even if you generate 1 billion of them, the chance that any two collide is less than 1 in ten quintillion.
I got a UUID whose third chunk doesn't start with 4
That's a UUID with a different version. That position simply shows the UUID's version number. A 1 means v1, which uses time and node information; 3 and 5 are versions built by hashing a name; 7 is v7, which puts a Unix millisecond timestamp up front. Nothing is malformed — it was just generated a different way. If a given spot only accepts v4, filter it out with a regular expression.
Can I store it as 32 characters without the hyphens?
Yes, and you can reverse it. Each chunk has a fixed length of 8-4-4-4-12, so putting the hyphens back requires no extra information. That said, if different systems mix formats, the same value ends up stored as different strings, so pick one convention for hyphens and letter case and stick with it. The tool's remove-hyphens option shows the generated value with only the hyphens stripped out.
Are UUIDs created in the browser sent to a server?
No. This tool creates values with the browser's built-in crypto.randomUUID(), and the UUIDs it generates are never sent to or stored on a server. The same goes for generating many at once by raising the count — and if you refresh the page, the list is gone.
This article was adapted from our Korean original. Read the Korean original