ULID generator
Generate ULIDs (Universally Unique Lexicographically Sortable Identifier)
ULID Generator
Universally Unique Lexicographically Sortable Identifier
TL;DR
What is ULID generator?
A ULID (Universally Unique Lexicographically Sortable Identifier) is a 128-bit identifier that encodes a 48-bit millisecond timestamp followed by 80 bits of randomness, represented as a 26-character Crockford Base32 string. ULIDs are designed to be both unique and naturally sortable by creation time.
How it works
The first 10 characters encode the Unix timestamp in milliseconds, and the remaining 16 characters are random. Because the timestamp is the most significant part, sorting ULIDs lexicographically also sorts them chronologically. Multiple ULIDs generated within the same millisecond are still ordered consistently using monotonic random increments.
Common use cases
- ‣Database primary keys: sortable IDs make range queries and pagination more efficient than random UUIDs
- ‣Event ordering: IDs that sort by creation time simplify event log queries without a separate timestamp column
- ‣Distributed ID generation: like UUIDs, ULIDs can be generated on any node without coordination
Frequently asked questions
When should I use a ULID instead of a UUID?
Use a ULID when lexicographic sort order matters. UUID v4 is random and does not sort by creation time. ULID gives you uniqueness plus time-ordered sorting, which improves index performance in databases like PostgreSQL and MySQL on timestamp-based queries.
Are ULIDs URL-safe?
Yes. ULIDs use Crockford Base32, which uses only uppercase letters A-Z (excluding I, L, O, U to avoid ambiguity) and digits 0-9. The output contains no special characters and is safe in URLs, file names, and database columns.
See also
- ‣UUIDs generator: UUID v4 is the standard choice when sort order does not matter and maximum ecosystem compatibility is more important than index performance
- ‣Token generator: for random secrets and API keys where a structured identifier format is not required, a plain random token avoids the overhead of a ULID