⟳ Generator
UUID v4 UUID v1 UUID v5 UUID v7 GUID Nil UUID
Bulk Generator UUID Validator How It Works FAQ Free Tools Contact
📖 Deep Dive

How UUIDs Work

A complete technical guide to UUID generation — how each version is structured, what makes them unique, and which to use in your system.

What is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit label used to identify information in computer systems. Defined by RFC 9562, UUIDs are designed to be globally unique without any central coordination authority. A UUID is represented as 32 hexadecimal digits grouped in the pattern 8-4-4-4-12, totalling 36 characters including hyphens.

550e8400-e29b-41d4-a716-446655440000
Field 1 (32 bits)
Field 2 (16 bits)
Version + Field 3 (16 bits)
Variant + Clock (16 bits)
Node (48 bits)
How UUID v4 is Generated

UUID v4 is the simplest and most widely used UUID version. It uses a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG) to fill 122 bits with random data. The remaining 6 bits are used for the version and variant markers.

1

Generate 128 random bits

The Web Crypto API (crypto.getRandomValues) generates 16 bytes of cryptographically secure random data. This is fundamentally different from Math.random() — it uses the operating system entropy pool.

2

Set version bits (position 49–52)

Bits 49–52 are set to 0100 (binary for 4). This sets the 13th hex character to 4 and is how you identify a v4 UUID.

3

Set variant bits (position 65–66)

Bits 65–66 are set to 10 (binary). This sets the 17th hex character to 8, 9, a, or b — the RFC 9562 variant marker.

4

Format as hexadecimal string

The 128 bits are converted to 32 lowercase hex characters and formatted with hyphens in the 8-4-4-4-12 pattern, producing the final UUID string.

Uniqueness: With 122 bits of randomness, the probability of generating two identical v4 UUIDs is 1 in 2122. Even at 1 billion UUIDs per second, you would need to generate them for 85 years before reaching a 50% chance of any collision.
How UUID v7 is Generated

UUID v7 is the recommended UUID version for database primary keys. It encodes a Unix millisecond timestamp in the first 48 bits, making UUIDs sortable by creation time.

1

Get Unix timestamp in milliseconds

Date.now() returns the current time as milliseconds since January 1, 1970. This is converted to a 48-bit integer and placed in the first 48 bits of the UUID.

2

Set version bits

Bits 49–52 are set to 0111 (7), making the 13th hex character 7.

3

Fill remaining bits with random data

The remaining 74 bits are filled with cryptographically secure random data, providing randomness within the same millisecond.

4

Set variant bits and format

Bits 65–66 are set to 10 (RFC 9562 variant). The result is formatted as a standard UUID string — but one that sorts lexicographically in time order.

Why this matters for databases: Random UUIDs (v4) cause B-tree index fragmentation because new rows are inserted at random positions. Time-ordered UUIDs (v7) are always inserted at the end of the index — exactly like auto-increment integers — giving the same performance while retaining UUID benefits.
How UUID v5 is Generated

UUID v5 is fundamentally different from v4 and v7: it is not random. Given the same inputs, it always produces the same output.

1

Choose a namespace

RFC 9562 defines four standard namespaces: DNS, URL, OID, and X500. Each namespace is itself a UUID. You can also define custom namespaces for your application's own naming hierarchy.

2

Concatenate namespace bytes + name bytes

The namespace UUID (16 bytes) and the name string (UTF-8 encoded) are concatenated into a single byte sequence. The name can be any string — a domain name, URL, email address, or any identifier.

3

Compute SHA-1 hash

SHA-1 is computed on the concatenated bytes, producing a 160-bit (20 byte) hash. The first 128 bits of this hash form the base of the UUID.

4

Set version and variant bits, format

Bits 49–52 are set to 0101 (5) and bits 65–66 are set to 10. The result is formatted as a UUID string — identical every time for the same namespace and name.

How UUID v1 is Generated

UUID v1 is the original time-based UUID, using a complex timestamp format and the MAC address of the generating machine.

1

Get timestamp in 100ns intervals since Oct 15, 1582

The UUID v1 timestamp counts 100-nanosecond intervals since the start of the Gregorian calendar reform. This is split across three fields: time-low (32 bits), time-mid (16 bits), and time-high (12 bits).

2

Generate clock sequence

A 14-bit clock sequence is maintained to prevent duplicates when the system clock is adjusted backwards. It is initialised randomly and incremented on each UUID generation within the same timestamp.

3

Add node (MAC address or random)

The original spec uses the MAC address of the network card as a 48-bit node identifier. UUIDCore uses a random node for privacy — exposing real MAC addresses is a security risk.

Security note: UUID v1 with a real MAC address can reveal which machine generated the UUID, when it was generated, and potentially other information. Always use a random node (as UUIDCore does) or switch to UUID v7 for new systems.
Choosing the Right Version
Featurev4 Randomv7 Sortablev5 Name-basedv1 Time-based
Generation methodRandomTimestamp + randomSHA-1 hashTimestamp + MAC
Time-ordered~
Deterministic
DB index friendly~
Timestamp extractable
Privacy safe~
RFC 9562 recommended✓ New systemsLegacy only
Best use caseGeneral purposeDB primary keysContent addressingLegacy/Cassandra

Ready to generate UUIDs?

Use our free generator — all versions, bulk generation, validator, and more.