UUID v4 vs v7: Random IDs or Time-Ordered IDs
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 and decode
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: 7
- Variant: RFC 9562 (the standard one)
- Created: 2025-10-28 14:32:43.614 (UTC)
All eight UUID versions
| 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 |
Code you can copy
UUID v4 in the browser or Node
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"UUID v7 without a library
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);
}Read the time from a v7 UUID
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();
Why ordering matters for databases
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.
Reading the layout
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.
How it works
- Press a generate button to make a fresh v4 or v7 UUID in your browser.
- Copy it, or paste any UUID into the decoder box.
- The decoder reads the version digit and the variant bits, and for v7 turns the first 48 bits into a date and time.
- Generate a few v7 values in a row and notice how their first characters barely change.
Tips
- Store UUIDs in a native uuid column where your database has one. Sixteen bytes beats a 36 character string for size and comparisons.
- Do not use v7 where the creation time is sensitive, such as password reset tokens. Anyone holding the ID can read when it was made.
- crypto.randomUUID() only works on secure pages (HTTPS or localhost). Over plain HTTP it is not available.
- Two v7 IDs made in the same millisecond are ordered by their random bits, not by which came first, unless your library uses the optional counter methods the RFC describes.
Frequently asked questions
What is the difference between a GUID and a UUID?
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.
Is UUID v7 an official standard?
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.
Is UUID v7 unique enough?
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.
Can I get the creation time back from a v7 UUID?
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.
Should I switch existing v4 keys to v7?
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.
Build your site free or see all free tools. On We.Inc you can build your site free, with no card and no trial needed to start. AI building is on paid plans from $20 a month.
More in Guides
- How to View Page Source
- View Transitions API Examples
- Vite vs Next.js: Which One Fits Your Project?
- WCAG 2.2 Checklist: All Level A and AA Criteria
- Web Design Contract Template: Free Checklist + Example
- Web Design Principles, Shown Not Told
- Web Design Proposal Template (Free Download + Filled Example) | How-to Guide
- 20 Web Dev Projects for Beginners (with Starter Code)
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App