UUID, ULID and NanoID: Which Unique ID Should You Use?
Developer · Published October 7, 2026 · Updated October 24, 2026 · 3 min read
Written by Akinrinmade Michael
Almost every app needs unique identifiers for users, orders and records. Using a random ID instead of a counter means you can create IDs anywhere, without asking a central database, and nobody can guess the next one. The question is which kind to use, and the answer depends on where the ID will live.
The four at a glance
| UUID v4 | UUID v7 | ULID | NanoID | |
|---|---|---|---|---|
| Length | 36 characters | 36 characters | 26 characters | 21 by default |
| Made from | 122 random bits | Timestamp plus random bits | Timestamp plus random bits | Random characters |
| Sorts by time | No | Yes | Yes | No |
| Reveals when it was made | No | Yes | Yes | No |
| Support | Everywhere | Growing | Libraries | Libraries |
UUID v4
The classic. It's 128 bits, of which 122 are random, written as 36 characters like 3f2b8c1e-7a4d-4f6b-9d2e-1c5a8b7e0f34. The 4 at the start of the third group marks the version, and the first character of the fourth group is 8, 9, a or b. The chance of two matching is so small it can be ignored: you'd need about 2.7 quintillion IDs for a 50 percent chance of a single repeat. It works everywhere, and nearly every language and database understands it.
UUID v7
A newer version that starts with a 48-bit timestamp in milliseconds, followed by random bits. New IDs sort after older ones. That helps databases, because inserts land near the end of an index instead of at random places, which is usually faster and keeps the index compact. The trade-off is that anyone who sees the ID can read roughly when it was made.
ULID
A 26-character ID that also starts with a timestamp, written in Crockford Base32, which skips the letters I, L, O and U to avoid confusion. The first 10 characters are the time and the last 16 are random. It's shorter than a UUID, easy to read aloud and sorts by time as plain text. For example, 01HF7YAT00BA9ET27H7DP6JCEM was made at the moment 1700000000000 milliseconds.
NanoID
A short random string, 21 characters by default, made from letters, numbers, _ and -. It's good for URLs and short links. You can choose the length and the characters, but a shorter ID or a smaller alphabet has fewer possible values, so collisions become more likely. A 21-character ID from the default 64 characters carries about 126 bits, similar to a UUID, and a 10-digit number carries only about 33.
Why sortable IDs help a database
Most databases keep a primary key in an ordered index. Random keys land in random places in that index, so the database keeps splitting and reshuffling pages, which wastes space and slows writes on big tables. A key that increases with time always goes at the end, like adding to a log. That's the main reason to pick UUID v7 or ULID for primary keys, and it matters most when a table grows to many millions of rows.
Storage size
A UUID is 16 bytes in binary but 36 characters as text. Many databases have a binary or native UUID type that stores the compact form, which is smaller and quicker than a text column. A ULID can be stored as 16 bytes too. A text column for a NanoID of 21 characters takes 21 bytes.
How to choose
- Need the safest, most widely supported choice? Use UUID v4.
- Storing rows in a database and want time order? Use UUID v7 or ULID.
- Need a short, friendly string for a URL? Use NanoID, and use enough characters for your volume.
- Don't want IDs to reveal when something was created? Avoid v7 and ULID, and use v4 or NanoID.
- Never use any of these as a secret. IDs identify things, but they aren't passwords or access tokens by themselves.
Mistakes to avoid
- Using a short numeric code for anything that has to be hard to guess.
- Putting a time-based ID in a public link when the creation time is sensitive.
- Generating IDs with a weak random function. Use the secure one built into your platform.
- Comparing IDs as case-sensitive strings when the format allows either case.
Try each type in the UUID Generator and the ULID & NanoID Generator. If you need a fixed fingerprint of some data instead of a random ID, that's what the Hash Generator is for.