Two web servers, a mobile app that works offline and a nightly import job can all create rows for the same table without asking each other which ID is still free. Version 4 UUIDs allow this by drawing 122 bits at random and relying on the space being too large to hit the same value twice. Whether that holds in a given system depends on two things the identifier itself cannot show: how many values get created, and which generator produced them. For a short introduction to UUIDs in general, see what a UUID is and how to generate one.

Telling a version 4 UUID apart from other versions

In any UUID that follows RFC 9562, the 13th character is its version number. In a random UUID it is always 4, and the 17th character is always 8, 9, a or b. Those two digits hold the only six bits that are not random:

  • The version field is the top 4 bits of the seventh byte (index 6). For version 4 those bits are 0100, so the 13th hex digit is 4.
  • The variant field is the top 2 bits of the ninth byte (index 8). UUIDs defined by RFC 9562 use the variant 10, so the 17th hex digit is binary 1000 to 1011: 8, 9, a or b.
3f2a9c1e-7b4d-4e8a-9c21-5d6f0b3a7e44
              ^    ^
              |    variant: 8, 9, a or b
              version: always 4

The value above is made up for illustration. The UUID Generator keeps both fixed positions in every value it produces. That includes the 32-character form without hyphens and the uppercase form, where the 17th character is 8, 9, A or B.

Why the fields have names that no longer fit

The 128-bit layout is older than random UUIDs. RFC 9562 says UUIDs "were originally used in the Apollo Network Computing System (NCS), later in the Open Software Foundation's (OSF's) Distributed Computing Environment (DCE)". The DCE 1.1 RPC specification divides the bits into time_low (32 bits), time_mid (16), time_hi_and_version (16), clock_seq_hi_and_reserved (8), clock_seq_low (8) and node (48), and describes the node as "the IEEE address, usually the host address". A timestamp combined with a network address gave each host its own range of identifiers, with no central registry.

The February 1998 revision of an Internet-Draft by Paul Leach (Microsoft) and Rich Salz (Certco) lists four versions, the fourth being "the randomly or pseudo-randomly generated version". RFC 4122 standardised the format in 2005, and RFC 9562 obsoleted it in May 2024. ITU-T X.667 | ISO/IEC 9834-8 standardises the same format on the ITU and ISO side.

In a version 4 UUID, none of the old fields holds a timestamp, a clock sequence or an address. The names survive only because the layout does. RFC 9562 fills the remaining 128 − 4 − 2 = 122 bits with random data: 48 bits in a field it calls random_a, 12 in random_b and 62 in random_c.

What the other digits in that position mean

RFC 9562 keeps versions 1 to 5, adds versions 6, 7 and 8, and defines the Max UUID alongside the existing Nil UUID. Every version uses the same 128-bit frame with the version digit in the same place, so the 13th character tells you what fills the rest:

Version What fills the other bits Sorts by creation time? Typical use or risk
1 60-bit timestamp in 100 ns units since 15 October 1582, clock sequence, node (often a MAC address) No, the low timestamp bits come first Legacy systems; exposes host and time
2 DCE Security version with embedded POSIX UIDs No Reserved for DCE; RFC 9562 does not detail it
3 MD5 hash of a namespace UUID plus a name No Deterministic IDs from names
4 122 random bits No General-purpose random IDs
5 SHA-1 hash of a namespace UUID plus a name No Deterministic IDs from names
6 The version 1 fields, reordered "for improved DB locality" (RFC 9562 §5.6) Yes Still carries node and time
7 48-bit Unix timestamp in milliseconds, then 74 bits of random data or counter Yes Database keys; reveals creation time
8 Layout defined by the implementer Depends Experimental or vendor-specific uses

Name-based versions work the opposite way to version 4: the same namespace and name always give the same UUID. Two systems can therefore derive a matching identifier for "example.com" without talking to each other (Python uuid docs).

Estimating the duplicate risk for your own volume

Collisions among random values follow the birthday problem. With N equally likely values and n values drawn independently, the probability that at least two are equal is approximately:

p ≈ 1 − e^(−n² / 2N)

For version 4, N = 2^122 ≈ 5.32 × 10^36, so 2N ≈ 1.063 × 10^37 (birthday problem). Find the row closest to the number of IDs your system will ever create:

UUIDs generated (n) n² / 2N Chance of at least one duplicate
10^9 (a billion) 9.4 × 10^-20 about 9.4 × 10^-20
10^12 (a trillion) 9.4 × 10^-14 about 9.4 × 10^-14
10^15 9.4 × 10^-8 about 1 in 10.6 million
10^18 0.094 about 9.0%
2.71 × 10^18 0.693 50%

When the exponent is small, p is almost exactly n²/2N, which is why the first three rows match. In the 10^18 row, 1 − e^−0.094 ≈ 0.090.

The 50% point comes from setting p = 0.5, which gives n²/2N = ln 2. So n = √(2N · ln 2) = 2^61 × √(2 ln 2) ≈ 1.1774 × 2.306 × 10^18 ≈ 2.71 × 10^18.

To work backwards from a risk you can accept, solve for n. A one-in-a-billion chance needs n²/2N = 10^-9, so n = √(1.063 × 10^28) ≈ 1.03 × 10^14, or about 103 trillion UUIDs.

To turn the 50% figure into time: generating 2.71 × 10^18 UUIDs at a billion per second takes 2.71 × 10^9 seconds. A year is about 3.156 × 10^7 seconds, so that is roughly 86 years of nonstop generation.

RFC 9562 still does not promise global uniqueness. Its collision-resistance section says implementations "should weigh the consequences of UUID collisions within their application" when choosing a version. Random UUIDs make collisions improbable, not impossible.

When the real number of states is far smaller

Every figure above assumes that each of the 122 bits is independent and uniformly random. A weak generator breaks that assumption without changing how the output looks. If a generator can only reach 2^32 distinct internal states, the effective N is 2^32, not 2^122. The same formula then puts the 50% point at about 1.18 × 2^16, or around 77,000 values. A badly seeded generator that repeats its sequence after a restart is worse still.

Checking where the randomness comes from

In JavaScript, the classic mistake is building UUIDs from Math.random(). The V8 team's 2015 post on Math.random says that even its improved xorshift128+ implementation is not cryptographically secure, and points to getRandomValues instead.

Browsers offer two better methods on the Crypto interface. The W3C Web Cryptography API Level 2 defines crypto.randomUUID() in terms of cryptographically secure random bytes. It fills 16 bytes, sets the four most significant bits of bytes[6] to 0100 and the two most significant bits of bytes[8] to 10, and returns the text form. The method is marked [SecureContext], so it exists only in secure contexts, such as HTTPS pages and localhost. MDN lists it as available across major browsers since March 2022, including in Web Workers.

The older crypto.getRandomValues() fills a typed array with random bytes, up to 65,536 bytes per call, and the specification does not restrict it to secure contexts. Building a version 4 UUID from it takes one mask per fixed field:

const bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);
bytes[6] = (bytes[6] & 0x0f) | 0x40; // version 4
bytes[8] = (bytes[8] & 0x3f) | 0x80; // variant 10
const hex = Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('');
const uuid = [hex.slice(0, 8), hex.slice(8, 12), hex.slice(12, 16),
              hex.slice(16, 20), hex.slice(20)].join('-');

The & 0x0f clears the top four bits, and | 0x40 writes 0100 into them. The & 0x3f clears the top two bits, and | 0x80 writes 10. The other 122 bits stay as the generator produced them.

For getRandomValues, the specification says implementations "should generate cryptographically strong random values using well-established cryptographic pseudo-random number generators seeded with high-quality entropy", such as an operating-system entropy source. The article on where password randomness comes from traces that chain from OS entropy to the browser's generator.

The UUID Generator uses crypto.randomUUID() when it is present. When it is not, for example on a plain http page, it falls back to exactly the masking shown above. It never falls back to Math.random(). If neither Web Crypto method exists, it shows the message "Secure random generation is unavailable in this browser." instead of producing weaker values. Each value is generated independently, and a batch is not checked for duplicates. With 122 good random bits, comparing 100 values would almost never find one.

Picking a primary key: random or time-ordered

The cost of version 4 shows up in indexes. A B-tree keeps its keys in sorted order. Sequential keys land at the right-hand edge and fill the same few pages, while random keys land anywhere. RFC 9562 says this directly: with UUID versions that are not time-ordered, such as version 4, "new values created in succession are not close to each other in the index; thus, they require inserts to be performed at random locations".

The effect is larger where the table lives inside its primary-key index. In MySQL's InnoDB, the clustered index is the primary key and holds the row data, so a random key decides where each row is physically written. Every secondary index record also contains the primary key columns, and the manual advises keeping the primary key short. A random 16-byte key therefore spreads writes across the table and makes every other index larger.

Storing the key as text makes it larger again. PostgreSQL's native uuid type uses 16 bytes, while the text form is 36 characters. RFC 9562 notes that binary storage "requires less space and may result in faster data access".

Version 7 avoids the scattering by starting with a 48-bit Unix millisecond timestamp, so later values sort later. ULID, an earlier format outside the RFCs, uses the same idea: a 48-bit millisecond timestamp and 80 random bits, written as 26 characters of Crockford Base32. The trade-off is that anyone who sees the value can read when it was created. RFC 9562 calls embedded timestamps "a very small attack surface", because they reveal the order of creation but nothing about the data itself.

Platforms are adding the newer versions. PostgreSQL has a built-in version 4 gen_random_uuid() from version 13 and uuidv7() from version 18. .NET pairs Guid.NewGuid() (version 4) with Guid.CreateVersion7() from .NET 9, and Python 3.14 added uuid6(), uuid7() and uuid8(). The UUID Generator produces version 4 only. For version 7 or name-based values, use your language's standard library or your database.

Deciding whether an ID can double as a secret

RFC 9562's security considerations are blunt: "Implementations SHOULD NOT assume that UUIDs are hard to guess. For example, they MUST NOT be used as security capabilities (identifiers whose mere possession grants access)."

Being hard to guess is not the same as being safe to rely on. 122 bits from a cryptographic generator do make a version 4 value impractical to guess, and RFC 9562 recommends a CSPRNG for generating the random bits. But identifiers travel. They show up in URLs, browser history, server logs, analytics tools and Referer headers, and they get pasted into tickets and chats. Holding an ID does not prove the right to use it, so the server still has to check whether the person asking may see the record.

Microsoft's NewGuid documentation recommends against using the method for cryptographic purposes. A version 4 UUID has a partly predictable bit pattern and carries at most 122 bits of entropy, while some security policies require 128 bits or more. A token meant to be secret should come from a dedicated random generator and have its own expiry and revocation.

Other versions leak more. RFC 9562 warns that a MAC address in the node field of version 1 creates "privacy and network security issues". Python's documentation notes that uuid1() "may compromise privacy since it creates a UUID containing the computer's network address". Version 6 carries the same fields, and version 7 reveals its creation time to the millisecond.

Fixing a lookup that misses an existing UUID

The symptom is usually one of two things. A lookup by ID returns nothing although the record exists, or a text column with a unique index holds the same UUID twice. The cause is usually spelling. A UUID is a 128-bit number, and hyphens and letter case only affect how it is displayed. RFC 9562 says hex digits are output in lowercase and are case-insensitive on input, but a plain string comparison does not apply that rule. "3F2A9C1E-…" and "3f2a9c1e-…" are the same UUID but different strings, and a copy without hyphens differs from both. The fix is to parse values into a native UUID type, or to normalise them to one spelling before comparing or indexing.

Platforms differ in what they produce, and that is how mixed spellings end up in one system. .NET's Guid.ToString supports five format specifiers: N (32 digits), D (hyphenated), B (hyphenated in braces), P (hyphenated in parentheses) and X (a structure of hex values in braces). PostgreSQL accepts uppercase digits, braces and missing hyphens, but always outputs the lowercase hyphenated form.

Raw bytes have their own trap. .NET's ToByteArray() writes the first three groups in reversed byte order, so the bytes do not match the RFC's network byte order even when the text matches. Code that moves GUIDs between .NET and other systems as raw bytes has to account for this.

If a target system expects a particular spelling, the tool covers the common text spellings directly. With Include hyphens turned off, it gives the 32-digit form that .NET calls N, and neither option changes the fixed version and variant digits.

For a system that stores UUIDs as text in capitals and compares them case-sensitively, Uppercase letters switches the hex digits a–f to A–F, so the version digit stays 4 and the variant digit becomes 8, 9, A or B. Combined with the hyphen setting, that gives four spellings of the same kind of value, which is enough to match the target system's existing rows instead of adding a fifth.

Privacy

The UUID Generator creates values in your browser with the Web Crypto API. The page's code does not send them over the network, and the TXT and CSV downloads are built locally.

FAQ

Why is the 13th character of a random UUID always 4?

It is the version field. RFC 9562 puts the version in the top four bits of the seventh byte, and the 13th hex digit shows exactly those four bits. A version 4 UUID stores 0100 there, which prints as 4. The variant bits also constrain the 17th digit, which is always 8, 9, a or b.

Can you tell when a version 4 UUID was created?

No. Apart from the six version and variant bits, a version 4 UUID is random data, so it contains no timestamp, counter or machine address. If you need the creation time, store it in a separate column, or use version 7, which embeds a millisecond timestamp.

Is a UUID v4 safe to use as a password-reset token or API key?

RFC 9562 says UUIDs must not be used as security capabilities, meaning identifiers whose mere possession grants access. A version 4 value from a cryptographic generator is hard to guess, but it is limited to 122 bits, and Microsoft advises against using NewGuid for cryptographic purposes. Use a token from a dedicated secure random generator, store it safely and give it an expiry.

Does a UUID generated on a plain http page have weaker randomness?

Not in browsers that follow the Web Crypto specification. crypto.randomUUID() is limited to secure contexts, but crypto.getRandomValues() is not. For getRandomValues, the specification says implementations "should" use cryptographically strong generators, and randomUUID is defined in terms of cryptographically secure random bytes. A generator that falls back to getRandomValues on http pages and sets the version and variant bits gets randomness from the same kind of cryptographic source in browsers that follow the specification. A fallback to Math.random() would not.

What are the Nil UUID and the Max UUID used for?

The Nil UUID has all 128 bits set to zero, and the Max UUID has all 128 bits set to one. Because they are fixed special values rather than generated ones, both work as sentinels, for example for "no value" or as an upper bound in a range. RFC 9562 defines both. The Max UUID is new in that RFC.

Why did RFC 9562 replace RFC 4122?

RFC 9562 lists problems with the older versions. The main ones are poor database-index locality and the privacy and network-security issues caused by embedding a MAC address in version 1. It addresses them by adding the time-ordered versions 6 and 7, version 8 for vendor-defined layouts, and the Max UUID, while keeping versions 1 to 5. It also expands the guidance on random sources and security.