ULID stands for Universally Unique Lexicographically Sortable Identifier. It was designed to fix two complaints about UUID v4: random identifiers do not sort by creation time, and the hyphenated 36-character form is longer than necessary. A ULID is 26 characters of Crockford base32, beginning with a 48-bit millisecond timestamp.
It is not a UUID. That distinction matters more than the length difference.
The format
01ARZ3NDEKTSV4RRFFQ69G5FAV
└──── 10 chars ────┘└─ 16 chars ─┘
timestamp randomness
- 48 bits of Unix milliseconds, encoded in 10 base32 characters.
- 80 bits of randomness, encoded in 16 base32 characters.
- Crockford base32 excludes
I,L,OandUto avoid confusion with digits. - Case-insensitive; canonical form is uppercase.
The result sorts lexicographically by creation time, assuming the timestamp is monotonic enough. Within the same millisecond, order depends on the random suffix.
Size and encoding
| Format | Characters | Binary size | Sortable | Standard |
|---|---|---|---|---|
| UUID v4 | 36 (hyphenated) | 128 bits | No | RFC 9562 |
| UUID v7 | 36 | 128 bits | By time | RFC 9562 |
| ULID | 26 | 128 bits | By time | Community spec |
| Integer | 1–20 | 64 bits typical | Yes | — |
A ULID stores the same 128 bits as a UUID, just in a denser alphabet. The string is shorter, but the underlying information is the same size. If your database stores BINARY(16), the storage cost is identical; the difference is the text representation and the sort order.
Where ULID helps
- Log correlation IDs that are easy to scan and sort.
- Client-generated IDs for offline-first apps.
- Public identifiers where a 26-character string is acceptable.
- Systems that want time ordering without v7 UUID library support.
- Case-insensitive inputs, since Crockford base32 avoids ambiguous characters.
Where it hurts
- APIs that validate the UUID shape reject it.
- Some databases and ORMs have native UUID types but no ULID type, so you store text or bytes and lose type-level validation.
- The specification is a community document, not an RFC. Tooling is good but less universal.
- It leaks creation time to the millisecond, just like v7.
- Lexicographic sorting in a database depends on collation; binary or
Ccollation is required for the expected order. A case-insensitive text collation can reorder values.
That last point is subtle. ULIDs are base32, and the alphabet is deliberately arranged so that digit order matches character order. But if the column uses a locale-aware collation, the database may not sort them the way you expect. Use a binary collation or store the value as bytes.
ULID versus UUID v7
They solve the same problem with different encodings:
| Property | ULID | UUID v7 |
|---|---|---|
| Time precision | 1 ms | 1 ms |
| Time bits | 48 | 48 |
| Random bits | 80 | 74 |
| String length | 26 | 36 |
| Standard | Community | RFC 9562 |
| Native DB type | Rare | Common |
| Human transcribable | Better | Hyphens help grouping |
UUID v7 has fewer random bits because it reserves 4 bits for the version and 2 for the variant. ULID has no version field, so it can use all remaining bits for randomness. Both are sufficient for practical collision resistance.
A decision checklist
- Does the consumer require a UUID? If yes, use v7 for time ordering or v4 for randomness.
- Is the identifier public and creation time sensitive? If yes, avoid both v7 and ULID; use v4.
- Is the column a database primary key with heavy inserts? Time-ordered formats help; measure the actual gain.
- Is human transcription part of the workflow? ULID's alphabet avoids ambiguous characters.
- Is tooling maturity a constraint? UUID has broader support.
- Does the database collation preserve byte order? Check before relying on sortability.
Generation and validation
A ULID generator needs a monotonic millisecond clock and a cryptographic random source. If the clock moves backwards, a naive generator can produce values that sort before earlier ones; better implementations detect this and increment the random component or wait.
Validation is a regex over the 26-character alphabet plus a timestamp decode. The first 10 characters decode to milliseconds since the epoch; the remaining 16 are random. Neither part is encrypted, so anyone can read the creation time.
ULIDs are a good default for internal identifiers where you control the stack and want sortable strings. UUIDs remain the better choice at boundaries, because every system already speaks them. The ULID generator and the UUID v7 generator let you compare the output side by side.