Home β€Ί UUID Generator (v4 & v7)

UUID Generator (v4 & v7)

UUID inspector

How the UUIDs are generated

Version 4 UUIDs come from crypto.randomUUID(), the browser's built-in generator backed by the operating system's cryptographically secure random source. 122 of the 128 bits are random; the remaining 6 bits encode the version (4) and the variant (8, 9, a or b at the start of the fourth group).

Version 7 UUIDs follow RFC 9562 (published in 2024): the first 48 bits are the Unix time in milliseconds, followed by the version nibble 7, 12 random bits, the variant bits and 62 more random bits. To keep IDs generated in the same millisecond in order, this generator increments the 12-bit field when the clock has not moved (the "monotonic counter" method from the RFC).

v4: 3f2504e0-4f89-4d3a-9a0c-0305e82c3301
                  ^    ^ version 4, variant 9
v7: 01936b2a-6c7e-7b41-8e9d-6f0a1c2b3d4e
    └─timestampβ”€β”˜ ^ version 7

v4 vs v7 at a glance

UUID v4UUID v7
Content122 random bits48-bit ms timestamp + 74 random bits
Sortable by timeNoYes
Index-friendly as primary keyPoor (random inserts)Good (append-mostly)
Leaks creation timeNoYes
Native supportEverywherePostgreSQL 18 uuidv7(), newer libraries

Gotchas

Frequently asked questions

Should I use UUID v4 or v7 for database primary keys?

For new tables, UUID v7 is usually the better choice. Its first 48 bits are a millisecond timestamp, so new IDs are roughly sorted by creation time and get inserted at the end of B-tree indexes, which reduces page splits and index bloat compared to fully random v4 IDs. Use v4 when you do not want IDs to reveal creation time.

Can two UUID v4 values collide?

In theory yes, in practice no. A v4 UUID has 122 random bits. You would need to generate about 2.7 quintillion (2.7 Γ— 10^18) UUIDs to reach a 50% chance of a single collision, assuming a proper random generator such as crypto.getRandomValues.

Are these UUIDs safe to use as secrets or tokens?

They are generated with the browser's cryptographically secure random generator, but UUIDs are designed as identifiers, not secrets. For session tokens or API keys use a dedicated token with at least 128 bits of entropy and no fixed structure. Never use v7 as a secret: half of it is a timestamp.

What is the difference between a UUID and a GUID?

Nothing meaningful. GUID is Microsoft's name for the same 128-bit identifier defined in RFC 9562 (formerly RFC 4122). Windows tools often display GUIDs in uppercase and wrapped in braces, which you can select in the format options.