UUID vs ULID vs Token Identifier Guide

UUID, ULID and random tokens are the three most common identifier types for developers. This guide compares their format, length, sortability and typical use cases so you can choose the right fit for database keys, API keys and session IDs.

IdentifierFormatLength / EntropySortableBest For
UUID v4xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx122 random bits + 6 version/variant bitsNo (fully random)Database keys, distributed IDs, privacy-sensitive IDs
UUID v7Timestamp (48 bits) + random (74 bits)128 bitsYes (monotonically increasing by time)New systems needing sortable primary keys
ULIDTTTTTTTTTTRRRRRRRRRRRRRRRR (Crockford Base32)48-bit timestamp + 80-bit randomnessYes (lexicographically sortable by generation time)URL-safe, sortable, human-readable identifiers
Random TokenHex / Base64 / Base62 stringAs needed (commonly 128–256 bits)NoAPI keys, sessions, activation codes, invite codes

Frequently Asked Questions

Can UUIDs collide?

UUID v4 collision probability is negligible: you would need to generate roughly 10^18 122-bit random UUIDs before expecting a single collision, far beyond normal business scale. UUID v7 and ULID add a time prefix; IDs generated in the same millisecond still have 80 bits of randomness, so collision risk remains negligible.

Should I choose UUID v4 or ULID?

Choose ULID when you need sortability, shorter URL representation and better readability. Choose UUID v4 for maximum compatibility and when you do not want to leak generation time. For new systems needing time-sortable primary keys, consider UUID v7 directly.

Which alphabet should a token use?

Hex is simplest and most readable; Base64 is shortest but includes +/= which can break URLs; Base62 strips special characters, balancing length and URL safety; Base58 also removes visually confusing characters (0/O, I/l), ideal for manual entry.

Should an API Key be a UUID or a random token?

API keys should use a cryptographically secure random token (at least 128 bits), not a raw UUID. UUIDs are designed for uniqueness; while they provide enough entropy, dedicated tokens give you control over length, alphabet and prefixes (e.g. sk_live_xxx), making permission scoping easier.