What is a ULID?
ULID (Universally Unique Lexicographically Sortable IDentifier) is a 26-character Crockford Base32 string: 48 bits timestamp (ms since Unix epoch) + 80 bits randomness. Because the timestamp comes first and Base32 keeps lexicographic order, sorting ULIDs as strings equals sorting by creation time — the property that makes them the go-to for database primary keys and distributed logs.
ULID vs UUID
- Sortable: UUID v4 is random — no ordering. ULID rows come out in insert order without an extra timestamp column.
- Compact: 26 chars vs 36; URL-safe without escaping.
- Monotonicity: within the same millisecond, ULIDs can bump randomness so they still sort (the spec's
monotonicoption). - UUID v7 is the IETF's time-sortable standard — same idea, different encoding. If your platform supports v7 natively, prefer it; otherwise ULID works everywhere as a plain string.
Uses
Primary keys in SQL (better insert locality than UUIDs), event IDs in logs (grep by time prefix), idempotency keys, and any place you want IDs that tell you when they were made — the decoder shows the exact millisecond.
Everything runs locally: no server, no tracking, IDs are generated with crypto.getRandomValues.
Formats, sizes and other limits
A ULID is 26 characters of Crockford Base32. ulid() takes the millisecond timestamp as a BigInt — plain numbers lose precision past 53 bits — and encodes it into the first ten characters, while randomBytes() fills the remaining eighty bits and encodeBase32() converts them. decodeUlid() reads the timestamp back, so you can tell when an identifier was created.
Where it stops working
Sortable but not unpredictable: the leading 48 bits are a timestamp, so generation time is exposed. The random tail comes from the platform CSPRNG, which is sound, but a collision inside the same millisecond is theoretically possible — the spec recommends monotonic handling that this page does not implement. There is no ULID-to-UUID conversion and nothing is stored.
Privacy: nothing is uploaded
Identifiers come from your device’s clock and random source. Nothing is transmitted and no registry is consulted.
Frequently asked questions
ULID or UUID?
ULID sorts by time and is shorter to read; UUID v4 is fully random, and v7 also embeds a timestamp. Pick by whether you want ordering.
Does it leak the creation time?
Yes — the first ten characters encode the millisecond. Consider that before exposing identifiers publicly.
Can two ULIDs collide?
Inside one millisecond it is theoretically possible. The specification suggests a monotonic counter; this page does not add one.