UUID v4 vs UUID v7 vs ULID
All three are 128-bit identifiers you can create without asking a database. They differ in one thing that matters a lot: whether newer IDs sort after older ones.
Last reviewed 2026-10-21. Bit layouts are from RFC 9562 (May 2024) and the ULID specification. Database effects are described qualitatively; benchmark with your own data.
Inspect an ID
The short answer
Use UUID v7 for new database keys when you want IDs that sort by creation time. Use UUID v4 when you want nothing derived from time, such as tokens that should reveal nothing. Use ULID if you want a shorter, URL-friendly text form and your tooling already supports it.
RFC 9562, published in May 2024, replaced RFC 4122 and defined UUID version 7, which puts a 48-bit Unix timestamp in milliseconds at the front. The same RFC notes that time-ordered UUIDs have better database-index locality than random ones.
Side by side
| Item | UUID v4 | UUID v7 | ULID |
|---|---|---|---|
| Defined in | RFC 9562, section 5.4 | RFC 9562, section 5.7 | ulid/spec on GitHub (community specification) |
| Total size | 128 bits | 128 bits | 128 bits |
| Random bits | 122 | 74 | 80 |
| Timestamp | None | 48-bit Unix time in milliseconds | 48-bit time in milliseconds |
| Text form | 36 characters, hex with hyphens | 36 characters, hex with hyphens | 26 characters, Crockford Base32 |
| Sorts by creation time | No | Yes, as bytes or as text | Yes, as text (order within one millisecond is not guaranteed unless you use the monotonic mode) |
| Reveals creation time | No | Yes, to the millisecond | Yes, to the millisecond |
| Database index behavior | Random inserts, poor locality | Mostly appends, good locality | Mostly appends, good locality |
Random bits for v4 and v7 are the figures in RFC 9562 (v7: 12 + 62 bits after the version and variant). ULID is 10 timestamp characters and 16 randomness characters.
Reading a UUID v7
The first 48 bits of a v7 UUID are a Unix timestamp in milliseconds. For example, the constructed value 018bcfe5-6800-7000-8000-000000000000 starts with 018bcfe5-6800, which is 1700000000000 milliseconds, or 2023-11-14T22:13:20.000Z. The remaining bits hold the version (7), the variant, and random data. This example is built by this page's code to show the layout; it is not a real identifier.
That timestamp is the privacy cost. Anyone who sees a v7 ID can tell when it was created. RFC 9562 notes that timestamps in a UUID are a small attack surface, so avoid v7 where creation time must stay secret.
Picking one
- Primary keys in a table that is mostly inserted and read recently: v7 or ULID.
- Public identifiers that should not leak order or timing, such as invite tokens: v4 (and for secrets, a purpose-built token, not a UUID).
- IDs shown to people or put in short URLs: ULID is 26 characters rather than 36.
- Existing systems that already store v4: keep them; mixing versions is allowed because they share one format.
Frequently asked questions
Is UUID v7 standardized?
Yes. RFC 9562, published in May 2024, defines versions 6, 7 and 8 and obsoletes RFC 4122.
Can I sort UUID v7 values as strings?
Yes, because the timestamp is the most significant part and the hex text is fixed width and lowercase or uppercase consistently. IDs created in the same millisecond order by their random bits unless your generator adds a counter.
Is ULID an RFC?
No. ULID is a community specification published on GitHub. It predates UUID v7 and solves the same sorting problem with a shorter text form.
Are UUID v4 collisions a practical concern?
With 122 random bits from a good random source, accidental collisions are not a practical concern at normal scale. The risk comes from a weak random number generator, not the format.
Sources
- RFC 9562: Universally Unique IDentifiers (UUIDs), May 2024 checked 2026-10-21
- ULID specification checked 2026-10-21