ulid

What is a ULID

ULID (Universally Unique Lexicographically Sortable Identifier) is a 128-bit id encoded as 26 characters of Crockford's Base32. It carries the same amount of information as a UUID, but in a shorter, case-insensitive string that sorts by creation time.

Anatomy of a ULID

The 128 bits split in two: the first 48 bits encode the creation timestamp in milliseconds (enough to last until the year 10889), and the remaining 80 bits are cryptographically secure randomness. The timestamp comes first, so ids created later are always greater as strings.

Lexicographically sortable

Sorting ULIDs alphabetically is sorting them chronologically. That makes them excellent database keys: new rows land at the end of the index instead of at random positions, avoiding the index fragmentation that purely random ids (UUID v4, Nano ID, CUID2) cause on write-heavy tables.

Crockford's Base32

The alphabet uses digits and uppercase letters but excludes I, L, O, and U to avoid confusion with 1 and 0 and accidental words. The result is case-insensitive, URL-safe, and easy to read aloud or transcribe — handy for ids that humans occasionally handle.

Monotonic within a millisecond

When multiple ids are created in the same millisecond, the spec defines a monotonic mode: the random part is incremented instead of regenerated, preserving strict ordering even under bursts. It is an opt-in factory in most implementations — plain generation just draws fresh randomness.

The trade-off: it tells time

The sortability comes from exposing the creation timestamp in plaintext — anyone holding a ULID can decode when it was made. That is exactly the information leakage CUID2 was designed to eliminate. If ids are public and creation time is sensitive, prefer a fully random format.

Collision resistance

Collisions are only possible within the same millisecond, where 80 bits of randomness allow over 10²⁴ distinct ids. In practice, two machines producing the same ULID is a non-event — no coordination required.

When to use it

The pick when you want time-ordered database keys with a compact, human-friendly encoding. UUID v7 offers the same idea as an official RFC standard with wider native database support; ULID answers with a shorter, case-insensitive string. If ordering does not matter and privacy does, CUID2 or Nano ID fit better.

© 2026 Unique ID Generator by meluiz