A UUID (Universally Unique Identifier) is a 128-bit identifier used to uniquely identify resources in distributed systems, databases and APIs. Its collision probability is so low that it is considered practically unique in any system.
UUID version 4 is the most common: it is generated pseudo-randomly according to the RFC 4122 standard. It is represented in hexadecimal with hyphens: 8-4-4-4-12 characters (xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx). UUID v4 is not sorted: successively generated UUIDs are not ordered, which can cause performance issues with B-tree indexes in databases. ULID (Universally Unique Lexicographically Sortable Identifier) solves this by embedding a timestamp in the first bits.
📐 Formula
📊 Reference table
| Format | Length | Sorted | Collision prob. | Use case |
|---|---|---|---|---|
| UUID v4 | 36 chars (with hyphens) | No | ~10⁻³⁶ | General ID, database |
| UUID v1 | 36 chars | Partial | ~10⁻³⁶ | ID with MAC timestamp |
| ULID | 26 chars | Yes (lexico.) | ~10⁻³⁶ | Sortable logs, events |
| NanoID | 21 chars (default) | No | ~10⁻³⁰ | Short URLs, compact IDs |
| Cuid2 | 24 chars | No | ~10⁻³⁶ | Secure ID, web |