ULID Generator
Generate Universally Unique Lexicographically Sortable Identifiers — sortable by time, encoded in Crockford Base32.
How to Use the ULID Generator
- Generate mode — click Generate ULID to create a single ULID. Enable Monotonic mode if you need guaranteed ordering within the same millisecond. The breakdown panel shows the timestamp and random components separately.
- Bulk mode — set a count from 1 to 100 and generate multiple ULIDs at once. Download as a text file or copy all to clipboard.
- Decode mode — paste any ULID to extract its embedded timestamp, see the exact creation time in ISO 8601 format, and inspect the random portion.
- Compare mode — enter two ULIDs to determine which was created earlier, the time difference between them, and whether they share the same millisecond timestamp.
What Is a ULID?
A ULID (Universally Unique Lexicographically Sortable Identifier) is a 128-bit identifier that solves a key limitation of UUID v4: random UUIDs have no inherent sort order. When used as database primary keys, random UUIDs cause index fragmentation because new rows insert at random positions rather than appending to the end of the B-tree index. ULIDs embed a millisecond-precision Unix timestamp in their first 48 bits, guaranteeing that ULIDs generated later will sort after earlier ones.
ULID Structure and Encoding
A ULID is encoded as a 26-character string using Crockford's Base32 alphabet: 0123456789ABCDEFGHJKMNPQRSTVWXYZ. This alphabet deliberately excludes the letters I, L, O, and U to eliminate visual confusion between similar-looking characters. The encoding breaks down as follows:
- Characters 1–10 (48 bits) — Unix timestamp in milliseconds. Supports dates from January 1, 1970 through September 4, 10889. Provides millisecond resolution.
- Characters 11–26 (80 bits) — Cryptographically secure random data generated using
crypto.getRandomValues(). Provides approximately 1.2 × 10²⁴ unique values per millisecond.
The total string is always exactly 26 characters, is case-insensitive, and is URL-safe with no special characters.
Monotonic Mode Explained
When generating multiple ULIDs rapidly, two ULIDs may share the same millisecond timestamp. Without monotonic mode, both would have independent random components — which could theoretically sort in the wrong order due to randomness. Monotonic mode addresses this by detecting same-millisecond generation and incrementing the random component by one instead of re-randomizing it. This guarantees strict lexicographic ordering even within a single millisecond, at the cost of marginally reduced randomness for batch-generated identifiers.
ULID vs UUID: Which Should You Use?
ULIDs and UUID v4 are both excellent identifiers with different trade-offs. Use ULIDs when you need sortable identifiers — for example, as primary keys in SQL or NoSQL databases where time-ordered retrieval is common, or in event-sourcing systems where events must be replayed in order. The embedded timestamp means ULIDs naturally cluster in database indexes, improving write and scan performance compared to random UUIDs.
Use UUID v4 when you need the widest ecosystem compatibility (RFC 4122 support is built into virtually every programming language and database), or when you specifically want to avoid leaking creation timestamps. For related identifier tools, see our UUID Generator and Hash Generator.
Crockford Base32 vs Standard Base32
Standard Base32 (RFC 4648) uses the alphabet A–Z and 2–7, which includes the ambiguous letters I, O, and L. Douglas Crockford designed an alternative alphabet specifically for human readability and robustness. Crockford Base32 uses digits 0–9 followed by letters A–Z minus I, L, O, U — making it harder to misread handwritten or printed identifiers. It also supports case-insensitive decoding, treating lowercase and uppercase as equivalent.
Practical ULID Use Cases
- Database primary keys — time-ordered primary keys improve B-tree index locality and reduce page splits
- Event sourcing — assign ULIDs to events so they naturally sort by occurrence order
- Log correlation — trace IDs that sort chronologically simplify log analysis
- Distributed systems — no central coordinator needed; each node generates its own ULIDs
- Cursor-based pagination — use ULIDs as stable page cursors that encode position in time
- File naming — sortable filenames that preserve upload order without extra metadata
ULID Implementations by Language
ULID is supported by libraries in most major languages: JavaScript/TypeScript (ulid npm package), Python (python-ulid), Go (github.com/oklog/ulid), Rust (ulid crate), Java (de.huxhorn.sulky:de.huxhorn.sulky.ulid), and PHP (robinvdvleuten/ulid). This tool implements ULID generation from scratch using the Web Crypto API for cryptographically secure random values, with no external dependencies.