UUID v4 vs v7 vs ULID vs KSUID: Which ID to Use
Short answer: UUID v4 vs v7 comes down to this. For a new database primary key, UUID v7 is usually the best default because it sorts by creation time. Use UUID v4 when the ID is public and its creation time must stay private. Use v5 when you need the same input to always give the same ID. ULID and KSUID are good when you want shorter, URL-friendly, sortable strings.
Generate and validate all of these in the UUID Generator. It runs in your browser using the secure random source (crypto.getRandomValues).
What a UUID is
A UUID (universally unique identifier) is a 128-bit value, written as 32 hexadecimal digits in five groups, for example 550e8400-e29b-41d4-a716-446655440000. Applications use UUIDs as database keys, request IDs and file names without needing a central server to hand out numbers.
The standard is now RFC 9562 (2024), which updated the older RFC 4122 and added versions 6, 7 and 8.
Why the version matters
Two things change with the version: how the ID is built and what it reveals. That affects database speed, privacy and sorting.
The core problem with v4 as a primary key
UUID v4 is almost entirely random (122 random bits). Databases such as PostgreSQL and MySQL store primary keys in a B-tree index, which works best when new rows are added at the end. A random key lands in a random spot every time. On large tables this means more page splits, a bigger and more fragmented index, and poorer cache use. On a small table or a read-heavy one you will probably never notice.
What v7 changes
UUID v7 starts with a 48-bit millisecond Unix timestamp followed by random bits (see how Unix timestamps work). New IDs sort roughly by creation time, so inserts land near the end of the index, much like an auto-increment number, while keeping the distributed, no-coordination benefit of a UUID. The cost: a v7 UUID reveals when it was created, to the millisecond.
The identifiers compared
| Type | Length | Sortable by time | Reveals creation time | Standard | Typical use |
|---|---|---|---|---|---|
| UUID v4 | 36 chars | No | No | RFC 9562 | Public IDs, tokens' companions, general default |
| UUID v7 | 36 chars | Yes (ms) | Yes | RFC 9562 | Database primary keys, event logs |
| UUID v1 / v6 | 36 chars | v6 yes, v1 no (clock bits reversed) | Yes | RFC 9562 | Legacy systems; v6 is a re-ordered v1 |
| UUID v3 / v5 | 36 chars | No | No | RFC 9562 | Deterministic IDs from a name |
| ULID | 26 chars | Yes (ms) | Yes | Community spec | Short sortable IDs, readable URLs |
| KSUID | 27 chars | Yes (seconds) | Yes | Community spec | Sortable IDs with a larger random part |
| NanoID | Configurable | No | No | Library, not a standard | Short random IDs with a custom alphabet |
UUID v3 and v5: name-based
v3 (MD5) and v5 (SHA-1) hash a namespace plus a name. The same pair always produces the same UUID, which is useful for stable IDs, for example turning a URL or an email address into a consistent identifier. Prefer v5 over v3. The hashing (MD5 and SHA-1 explained) is used for identity here, not for security, and the result does not reveal the name.
ULID
A ULID is 26 characters using Crockford's base32: a millisecond timestamp followed by random bits. It is case-insensitive, URL-safe and sorts lexicographically. In the generator, IDs created in one batch sort ascending even within the same millisecond.
KSUID
A KSUID is 27 characters: a 4-byte timestamp in seconds (counted from Unix time 1,400,000,000, which is 13 May 2014, 16:53:20 UTC) followed by 16 random bytes. It has more randomness than a ULID and a coarser clock.
NanoID
NanoID creates short random IDs from an alphabet you choose. The tool uses rejection sampling so every character in your alphabet is equally likely, and the alphabet must not repeat a character.
How to choose
- New table, many inserts, internal key: UUID v7.
- ID is exposed publicly, and you do not want to reveal creation time or growth rate: UUID v4, or a v7 internally with a separate random public ID.
- Same input must always give the same ID: UUID v5.
- Short, readable URL IDs that sort by time: ULID.
- Short random IDs with a custom alphabet: NanoID.
- Authentication, sessions, password-reset links: none of these. A UUID is an identifier, not a secret. Use a dedicated long random token instead (see strong random passwords and entropy).
Many recent databases and libraries support v7 directly. For example, PostgreSQL 18 (released September 2025) added a built-in uuidv7() function. Check your database and library documentation for your version.
How to generate and compare UUID v4 vs v7 with the UUID Generator
- Open the UUID Generator.
- Choose version 4 or version 7, set a quantity (up to 1000), and optionally uppercase or remove hyphens.
- Open More identifier types for v1, v6, v3, v5, ULID, KSUID, NanoID and the nil UUID. For v3/v5, pick a namespace (or enter a custom one) and list names one per line.
- Use Validate a UUID to check up to 200 values. It accepts the standard 8-4-4-4-12 form, 32 digits without hyphens,
{braces}and theurn:uuid:prefix, in any case. It shows the version, variant and, where present, the embedded time (UTC). - Copy the results.
Limits to know
- The validator checks structure only. It cannot tell whether a UUID is already in use.
- A v3 or v5 UUID does not reveal its original name.
- A v1 UUID that contains a real hardware address in its node field can identify the machine that made it. This tool uses a random node value with the multicast bit set, so it can never be a real network card address.
- Generation is limited to 1000 identifiers at a time, and validation to 200 lines.
- CUID2 is not offered.
- v7 helps mainly with write performance and range scans. It is not a magic speed-up for every read query.
Frequently asked questions
Is UUID v7 better than v4? For database primary keys on write-heavy tables, usually yes. For public identifiers where timing should stay private, v4 is better.
Does UUID v7 leak information? Yes, its creation time to the millisecond. Do not use it where that matters.
Are UUIDs unique? Practically. With 122 random bits, v4 collisions are astronomically unlikely in normal use. They are not mathematically impossible.
UUID v7 or ULID? Both sort by time and hold 128 bits. v7 is an official standard with native database support growing. ULID is shorter and nicer to read in URLs.
Can I use a UUID as a password or API key? No. Use a long, random secret generated for that purpose, and see the Password Generator.
Related tools and guides
- Hash Generator: v3 and v5 UUIDs are built from MD5 and SHA-1 (see MD5 vs SHA-256 vs SHA-3 vs BLAKE2)
- Timestamp Converter to read the time inside a v7 or ULID
- Password Generator
- Slug Generator for readable URL parts
- Base64 Encoder & Decoder