About ULID Generator
A ULID is a 26-character identifier that is globally unique like a UUID but adds a key advantage: its first 48 bits are a millisecond timestamp, so generated IDs are naturally time-ordered and sortable. This tool generates spec-compliant ULIDs locally using the browser's cryptographically secure random source, encoded in case-insensitive Crockford Base32 that drops ambiguous characters, and can emit them in bulk. Every ID is computed locally with no network call, ideal for database primary keys, log entries, or events that need to be both unique and time-sortable. Sortability is the core selling point and understanding what it sorts by is what makes it usable. The leading segment encodes the creation instant, so lexicographic order equals chronological order, which beats a purely random identifier in databases that retrieve by time or paginate; the trailing segment is random and distinguishes records within one instant. Because time lives in the front, ordering stability at high generation rates depends on monotonic handling. Whether order holds within one millisecond depends on the implementation. If the random part is generated independently, several records from the same millisecond sort arbitrarily, while a monotonic implementation guarantees a later-generated value sorts higher and preserves the intuition that earlier comes first. Before using it as a primary key with order-dependent pagination, confirm this or pagination may duplicate or skip at boundaries. Clock rollback breaks the time-ordered premise and must be considered in distributed settings. When a synchronisation mechanism moves an instance clock backwards, a newly generated identifier may carry an earlier time than ones already issued and ordering breaks. Without rollback detection and a wait or fallback, equal values can even be produced in one instant. Learn how the library handles rollback rather than assuming clocks only move forward. The encoded form and letter case must align with the storage layer. One dataset has several string representations, some using all uppercase alphanumerics and others including easily confused characters. If storage normalises case-insensitively, comparisons between the two forms differ from expectations, and string ordering also follows the database collation, so where time ordering matters, confirm the collation matches the character set order. Finally, it does not suit every identifier case and trades off against random identifiers. Random identifiers distribute evenly and reveal no creation time, suiting cases where the outside must not infer when a record was made; time-ordered ones are index-friendly and easy to paginate at the cost of exposing the instant. Which to pick depends on whether you need range queries by time and whether leaking creation time matters.
How It Works Internally
The identifier has two parts: a 48-bit millisecond timestamp followed by 80 random bits, encoded in 26 sortable characters. It is therefore time-ordered like UUID v7 while being shorter — the same 128 bits in 26 characters rather than 36. The trade-off is an alphabet that is case-insensitive and needs stating separately.
Generating two identifiers in the same millisecondThe time prefix is identical and only the random part differs, so order within a millisecond is arbitrary and says nothing about sequenceMeasured on This Page
| Structure | All 8 are 26 characters: 10 for time plus 16 random, per the ULID spec |
|---|---|
| Alphabet | Crockford base32 only (0-9 and A-Z minus I/L/O/U) — avoids I/1 and O/0 confusion when transcribed by hand |
| Timestamp | The first 10 characters decode to a millisecond timestamp matching generation time (e.g. 1,793,412,479,478) |
| Uniqueness | All 8 random suffixes differ (crypto.getRandomValues, 256 mod 32 is unbiased) |
| Sortability | Lexicographic order equals time order (random within a millisecond) — the core advantage over UUIDv4 |
Crockford base32 is the reason LEET-style short ids like 01ARZ3NDEKTSV4RRFFQ69G5FAV avoid the worst hand-copy errors: I, L, O and U are simply absent from the alphabet, so 1/I and 0/O cannot be confused and there is no accidental profanity of the U variety. 26 characters hold 130 bits — 48 of millisecond clock plus 80 of randomness — which is why a lexicographic sort is also a chronological sort, letting a plain B-tree index serve range queries over time. The 80-bit tail keeps collision odds negligible, but only if it comes from a CSPRNG (256 mod 32 divides evenly here, so no modulo bias either).
How to Use
- Open "ULID Generator"
- Set the count and toggle lowercase output
- Click "Regenerate" to produce the batch
- Copy one ID, or use "Copy all" to grab the batch
- Each row shows the decoded millisecond timestamp
Use Cases
- Sortable primary keys — Use ULIDs as DB primary keys so insert order matches time, aiding range queries and index locality.
- Log/event IDs — Assign time-sortable unique IDs to logs or event streams to trace ordering.
- Distributed generation — Multiple nodes generate collision-free, roughly ordered IDs without coordination.
- Replace auto-increment — Get ordered IDs without revealing record counts, safer than sequential keys.
- Bulk pre-generation — Produce many ULIDs at once for bulk imports or pre-allocated identifiers.
- Event sourcing IDs — Generate ULIDs for event store entries so replay order matches the original event timeline.
- Migration key mapping — Pre-generate ULIDs for new rows before a data migration to keep foreign key references intact.
FAQ
How do I choose between ULID and UUID?
Pick UUID for pure randomness and broad standard compatibility; pick ULID for time ordering and friendlier DB indexes. The ULID time prefix keeps new rows at the end, avoiding the index fragmentation random UUIDs cause. Use our UUID generator if you need a UUID.
Is a ULID strictly monotonic?
It increases with time at millisecond granularity, but the order of multiple ULIDs within the same millisecond is set by the random part. The spec offers a monotonic mode that increments the random bits within a millisecond for strict ordering.
Why Crockford Base32?
This encoding drops characters like I, L, O, and U that confuse with digits or spell unwanted words, is case-insensitive, and is friendlier for hand-copying and use in URLs.
Does a ULID expose its creation time?
Yes. The first 10 characters decode to a millisecond timestamp, which is a plus when you need ordering, but if you do not want to reveal creation time, switch to a purely random identifier.
Can 26 characters collide?
The timestamp takes 48 bits and the random part 80 bits. A collision within the same millisecond would require generating an astronomical number of IDs, so in practice they are unique.
Is ULID faster to generate than UUID?
They are essentially the same order of magnitude. The timestamp comes from the system clock and the random part from a single cryptographically secure call — purely local, with no network or coordination, so it easily serves high-throughput flows producing an ID per request. If you ever need a huge burst of ULIDs within a single millisecond, the spec's monotonic mode increments the random bits for strict ordering. In practice no caching or pre-generation is required to hit performance targets.
Does ULID really reduce database index fragmentation?
Yes — that is its main advantage over random UUIDs. The 48-bit millisecond prefix puts new IDs mostly at the tail of the index, making writes near-append-only with higher page-hit ratios, fewer splits, and friendlier range reads. Ordering, however, is only at millisecond granularity; multiple IDs within the same millisecond remain random-ordered. For strict global ordering across nodes, look at a snowflake-style scheme; when all you need is sortable and unique, ULID is usually the lighter, well-specified choice.
ULID or UUIDv4 for a database primary key?
ULID is time-ordered, which keeps B+ tree inserts sequential; random UUIDv4 causes page splits. Choose ULID when you want chronological order from a single generator, and UUIDv4 when you need no time leakage and collision-free generation across nodes.