UUID & ULID Generator
Generate cryptographically random UUID v4, time-based UUID v1, and ULID values. Bulk generation up to 100 at once.
Generate Unique Identifiers
UUID Validator
What Is a UUID?
A UUID (Universally Unique Identifier) is a 128-bit label used to uniquely identify information in computer systems. The standard format is 550e8400-e29b-41d4-a716-446655440000 — 32 hexadecimal digits separated by four hyphens. UUIDs are designed to be globally unique without requiring a central registration authority. The probability of generating two identical UUID v4 values is astronomically low — approximately 1 in 5.3 × 1036 — meaning you could generate one billion UUIDs per second for 86 years before having a 50% chance of a single collision.
UUID Versions Explained
| Version | Generation Method | Deterministic? | Best Use Case |
|---|---|---|---|
| v1 | Timestamp + MAC address | No (time-based) | Distributed systems needing time-ordered IDs |
| v3 | MD5 hash of namespace + name | Yes | Content-addressable IDs from known inputs |
| v4 | 122 random bits | No (random) | General purpose — database PKs, session IDs, API keys |
| v5 | SHA-1 hash of namespace + name | Yes | Same as v3 but with stronger hash (preferred over v3) |
| v7 (new) | Unix timestamp + random bits | No (time-based) | Database PKs that need to be sortable by creation time |
UUID v4 — The Default Choice
UUID v4 is the most widely used version. It generates 122 random bits (the remaining 6 bits encode the version and variant). The result is cryptographically random and unpredictable, making it suitable for security-sensitive use cases like session tokens and API keys. Most modern programming languages have built-in UUID v4 generation: crypto.randomUUID() in JavaScript, uuid.uuid4() in Python, UUID.randomUUID() in Java, and Str::uuid() in Laravel.
UUID vs Auto-Increment — The Database Debate
Traditional databases use auto-incrementing integers (1, 2, 3...) as primary keys. UUIDs offer several advantages but come with trade-offs:
| Factor | Auto-Increment | UUID v4 | ULID / UUID v7 |
|---|---|---|---|
| Storage Size | 4–8 bytes | 16 bytes | 16 bytes |
| Index Performance | Excellent (sequential) | Poor (random, causes B-tree fragmentation) | Good (time-sorted prefix) |
| Generate Without DB | No (needs DB round-trip) | Yes (generated anywhere) | Yes |
| Merge/Replicate Data | Collision risk | Safe | Safe |
| Exposes Record Count | Yes (ID #1000 = ~1000 records) | No (random, no info leak) | Partially (reveals timing) |
What Is ULID?
ULID (Universally Unique Lexicographically Sortable Identifier) is a 128-bit identifier designed to address UUID v4's biggest weakness: poor database index performance due to randomness. A ULID has the format 01ARZ3NDEKTSV4RRFFQ69G5FAV — 26 characters using Crockford's Base32 encoding. The first 48 bits encode the Unix timestamp in milliseconds, and the remaining 80 bits are random. This means ULIDs created at the same millisecond sort chronologically by creation time, while remaining globally unique.
ULIDs are increasingly preferred over UUID v4 for database primary keys because their time-sorted prefix keeps B-tree indexes efficient (new inserts always go at the end, like auto-increment). They are also shorter than UUIDs when displayed (26 chars vs 36) and URL-safe by default.
What Is NanoID?
NanoID is a tiny, URL-friendly unique ID generator. Default format: V1StGXR8_Z5jdHi6B-myT (21 characters, using A-Za-z0-9_-). It is 40% faster than UUID v4 in JavaScript and generates shorter IDs that are safe for URLs, HTML attributes, and file names. NanoID's alphabet and length are customizable — a 21-character NanoID has roughly the same collision probability as UUID v4.
When to Use Each Format
- Database primary keys: ULID or UUID v7 (time-sorted, good index performance)
- Session tokens / API keys: UUID v4 (pure random, unpredictable, no timing information)
- Distributed event IDs: ULID or UUID v1 (time-ordered for log analysis)
- Deterministic IDs from content: UUID v5 (same input always produces same UUID)
- Short IDs in URLs: NanoID (shorter, URL-safe, customizable length)
- Microservices / event sourcing: ULID (sortable, mergeable, no coordination needed)
Frequently Asked Questions — UUID Generator
UUID (Universally Unique Identifier) is a 128-bit identifier formatted as 32 hexadecimal digits in five groups (e.g., 550e8400-e29b-41d4-a716-446655440000). Used to uniquely identify database records, API resources, session tokens, and distributed system objects without a central coordinator. The probability of collision with UUID v4 is astronomically low — roughly 1 in 5.3 × 10³⁶ for any two random UUIDs.
UUID v1 is time-based — generated from the current timestamp and MAC address, making it time-ordered but potentially revealing machine identity. UUID v4 is random — generated from 122 random bits, the most widely used version for general-purpose IDs. UUID v5 is name-based — a deterministic SHA-1 hash of a namespace + name, always producing the same UUID for the same input, useful for content-addressed IDs.
ULID (Universally Unique Lexicographically Sortable Identifier) encodes a millisecond-precision timestamp in the first 10 characters, followed by 16 random characters. Unlike UUID v4, ULIDs are naturally sortable by creation time, making them better for database primary keys where you want both uniqueness and chronological ordering. They're also encoded in Crockford Base32 (no hyphens), making them shorter and URL-safe.
UUID v4 uses a cryptographically secure pseudo-random number generator (CSPRNG). While technically finite, the probability of generating a duplicate is negligible: generating 1 billion UUIDs per second for 100 years would have a 50% chance of a single collision. In practice, UUIDs are treated as unique. The security depends on the quality of your CSPRNG — always use platform-provided cryptographic randomness.
Auto-increment integers are simpler, smaller (4–8 bytes vs 16), and faster for indexed lookups. UUIDs are better when: merging data from multiple databases, exposing IDs in URLs (integers reveal record count), or generating IDs client-side before inserting. Use ULID or UUID v7 (time-ordered) if you need UUIDs but want the index performance benefits of sequential IDs.