← Hashito System Home 日本語 Tools Blog
Generate

ULID structure and when to use it

Structure (timestamp plus randomness)

A ULID is 128 bits: the first 48 bits are milliseconds since 1970 and the remaining 80 bits are random. It is encoded in Crockford Base32 (A-Z and digits, excluding ambiguous letters) into a 26-character string. Because the timestamp comes first, ULIDs generated in different milliseconds sort in creation order.

ULID vs UUID

Use UUID v4 when you only want randomness, and ULID when you want a time-ordered primary key. ULIDs tend to insert near the end of a B-tree index, reducing fragmentation. If you must not leak creation time, prefer a random UUID v4 instead.

Lowercase output and count

The canonical ULID form is uppercase, but you can output lowercase for systems that expect it (the value is the same). You can generate up to 1000 at once. Randomness uses crypto.getRandomValues.

Frequently asked questions (FAQ)

What is a ULID?

A 128-bit unique identifier whose first 48 bits are a millisecond timestamp and remaining 80 bits are random. It is encoded as a 26-character Crockford Base32 string and sorts in creation order as plain text. It is used as a UUID alternative.

How is ULID different from UUID?

UUID v4 is fully random with no sort order, while ULID's leading timestamp makes lexical order equal creation order. ULIDs are 26 characters (vs 36 for UUID) with no hyphens, so they are also URL-friendly.

Are the generated ULIDs safe?

Yes. They are generated entirely in your browser using the cryptographically secure crypto.getRandomValues. Nothing is sent to a server.