Both are 128-bit identifiers written as 36 characters. A v4 UUID is 122 random bits, so new values land anywhere in a sorted index. A v7 UUID starts with a 48-bit Unix timestamp in milliseconds followed by random bits, so values sort roughly by creation time. RFC 9562 recommends v7 over the older time-based v1 and v6.
| UUID v4 | UUID v7 | |
|---|---|---|
| Made from | 122 random bits | 48-bit millisecond timestamp plus 74 random bits |
| Sort order | Random | Roughly by creation time |
| Reveals creation time | No | Yes, to the millisecond |
| Built into browsers | crypto.randomUUID() | No, use a few lines of code or a library |
| Good for | Tokens, public IDs, anything that must not leak timing | Database primary keys, logs, event IDs |
Updated
Picking a UUID version is mostly a database question. Random v4 keys scatter inserts across an index, while v7 keys arrive in order, the same way an auto-increment number would, without needing a central counter. Generate both kinds below, then paste any UUID to see its version and, for v7, the moment it was made.
Generate v4, Generate v7
Press a button to make a UUID. It is created in your browser and never sent anywhere.
Paste a UUID to decode
019a2b3c-4d5e-7f60-8a1b-2c3d4e5f6a7b| Version | Built from | Notes |
|---|---|---|
| 1 | Gregorian time plus a node ID, often the MAC address | Legacy; prefer v7 |
| 2 | DCE Security version, not specified by RFC 9562 | Rare |
| 3 | Name-based, MD5 hash of a namespace and a name | Same input, same UUID |
| 4 | Random or pseudorandom bits | The common default |
| 5 | Name-based, SHA-1 hash of a namespace and a name | Preferred over v3 |
| 6 | v1's timestamp reordered so values sort by time | Prefer v7 for new systems |
| 7 | Unix Epoch time in milliseconds plus random bits | Sortable keys |
| 8 | Custom layout chosen by the implementation | Experimental or vendor formats |
Built in to current browsers on secure pages and to Node 19 and later through the global crypto object. Returns a 36 character string.
const id = crypto.randomUUID();
console.log(id); // e.g. "3f6c1b2a-9d4e-4c8b-a1f0-7e2d5b9c6a13"Writes the current time into the first six bytes, then sets the version and variant bits. The rest stays random.
function uuidv7() {
const b = crypto.getRandomValues(new Uint8Array(16));
const ms = Date.now();
for (let i = 0; i < 6; i++) b[i] = Math.floor(ms / 2 ** (8 * (5 - i))) & 0xff;
b[6] = (b[6] & 0x0f) | 0x70; // version 7
b[8] = (b[8] & 0x3f) | 0x80; // RFC 9562 variant
const h = Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
return h.slice(0, 8) + "-" + h.slice(8, 12) + "-" + h.slice(12, 16) + "-" + h.slice(16, 20) + "-" + h.slice(20);
}The first 12 hex digits are milliseconds since 1970, so parsing them gives a Date.
function v7Date(uuid) {
const ms = parseInt(uuid.replace(/-/g, "").slice(0, 12), 16);
return new Date(ms);
}
v7Date("019a2b3c-4d5e-7f60-8a1b-2c3d4e5f6a7b").toISOString();
Most databases keep primary keys in a B-tree. When each new key is larger than the last, inserts go to the end of the tree and recently written pages stay in memory. Random keys force writes into pages all over the tree, which means more page splits and more disk reads as a table grows.
RFC 9562 lists this locality problem as one of its reasons for adding time-ordered versions, and v7 is the one it points new systems toward.
In the text form, the 13th hex digit (the first of the third group) is the version, so a v7 UUID always has a 7 there and a v4 has a 4. The first digit of the fourth group is 8, 9, a or b for the standard variant.
For v7, the 12 digits before the version are the timestamp. Everything after the version digit, apart from the two variant bits, is random.
None that matters in practice. RFC 9562 defines UUIDs and notes they are also known as GUIDs, Globally Unique Identifiers, the name Microsoft tools use. A GUID generated by .NET or SQL Server is a UUID in the same 36 character format.
Yes. RFC 9562, published in 2024, defines versions 6, 7 and 8 alongside the older ones and obsoletes RFC 4122, the document that described UUIDs before.
Each millisecond has 74 random bits to spread across, which is plenty for almost any system. Collisions would need enormous numbers of IDs created in the very same millisecond.
Yes. The first 12 hex digits are the Unix time in milliseconds. Paste one into the decoder above to see it as a date, or parse those digits as a hexadecimal number yourself.
Usually not. Both are valid UUIDs and can live in the same column, so new rows can use v7 while old rows keep their v4 values. Rewriting primary keys means rewriting every foreign key that points at them.
Related: UUID generator, Unix timestamp converter, Hash generator, Base64 encoder and decoder.
Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.
We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.