Guide
Understanding UUID version 4
By Logappradeep · ServiceNow developer
A UUID (Universally Unique Identifier), called a GUID in the Microsoft world, is a 128-bit value used to identify something without asking a central authority for the next number. Any machine can generate one at any time, and the result is, for practical purposes, unique across every system on the planet. The format is now specified in RFC 9562, which replaced the long-standing RFC 4122 in 2024.
Anatomy of a UUID
UUIDs are written as 32 hexadecimal digits in five groups separated by hyphens, in an 8-4-4-4-12 pattern:
3f2b8c1e-9d4a-4e7b-a6c2-1f5e8d9b0a47
^ ^
version variant
The first digit of the third group is the version, always 4 for random UUIDs. The first digit of the fourth group encodes the variant and is always 8, 9, a, or b for standard UUIDs. Those fixed bits use 6 of the 128, leaving 122 random bits.
How unlikely is a collision?
With 2^122 possible values, the birthday paradox says you would need to generate about 2.7 × 10^18 (2.7 quintillion) version 4 UUIDs before reaching a 50% chance of a single duplicate. At a billion UUIDs per second, that takes around 86 years. In practice, collisions come from broken random number generators, cloned virtual machines with identical seeds, or copy-paste mistakes, not from the math. This generator uses the browser's crypto.randomUUID(), which draws from a cryptographically secure source.
Where UUIDs are useful
- Database primary keys that can be created by clients or across shards without coordination.
- Idempotency keys for payment and API requests, so a retried request is not processed twice.
- Correlation and trace IDs that follow a request through logs and services.
- File and object names in storage buckets, where predictable names could collide or be guessed.
- Test fixtures and seed data that need realistic identifiers.
Practical considerations
- Index performance. Random v4 values scatter inserts across a B-tree index, which can slow down write-heavy tables. RFC 9562 introduced UUIDv7, which begins with a timestamp so new values sort roughly in creation order; consider it for primary keys.
- Storage. Store UUIDs in a native
uuidcolumn type or as 16 bytes of binary rather than a 36-character string, which more than doubles their size. - Case and hyphens. Lowercase with hyphens is the canonical form. The Uppercase and Remove hyphens options suit systems that expect those styles, but parsers should accept any case, so compare UUIDs case-insensitively.
- Not an access control. A v4 UUID is hard to guess, but if it appears in a URL it can leak through logs and browser history. Do not treat knowing an ID as proof of permission.
UUIDs are generated locally in your browser.