UUID (Universally Unique Identifier)
A UUID is a 128-bit identifier written as 32 hexadecimal digits in an 8-4-4-4-12 pattern, designed so that values can be generated independently anywhere with a negligible chance of collision. The current specification is RFC 9562.
Anatomy
A UUID is 16 bytes, normally shown as lowercase hex with hyphens:
f47ac10b-58cc-4372-a567-0e02b2c3d479
^ ^
| variant (8, 9, a or b)
version (here 4)
The first digit of the third group is the version, and the first digit of the fourth group encodes the variant. In a version 4 UUID, 6 of the 128 bits are fixed for those two fields and the remaining 122 bits are random.
Versions you will meet
| Version | How it is made |
|---|---|
| v1 | A timestamp plus a clock sequence and a node identifier (historically a MAC address) |
| v3 / v5 | A hash of a namespace and a name: MD5 for v3, SHA-1 for v5. The same input always gives the same UUID |
| v4 | Random. By far the most common |
| v7 | A 48-bit Unix millisecond timestamp followed by random bits, so values sort by creation time |
RFC 9562 also defines v6 (a reordered v1) and v8 (application-defined), plus the special all-zero “nil” and all-ones “max” values.
How unique is “unique”?
With 122 random bits, you would need to generate roughly 2.7 quintillion (2.7 × 10¹⁸) v4 UUIDs before the chance of even one collision reaches 50%. In practice collisions come from bad random number generators or copied data, not from bad luck.
Common pitfalls
- Weak randomness. A v4 UUID is only as unpredictable as its source. Use a cryptographically secure generator such as the browser’s
crypto.randomUUID(), neverMath.random(). - Random UUIDs as database primary keys. Fully random values scatter inserts across an index, which can hurt write performance at scale. Time-ordered UUIDs like v7 keep new rows together.
- Treating a UUID as a secret. A UUID identifies something. Unless it came from a secure generator and you are deliberately using it as an unguessable token, do not rely on it for access control.
- Storing them as strings. A UUID is 16 bytes, and most databases have a native type that uses that. A 36-character string takes more than twice the space.
- Case and formatting. UUIDs are case-insensitive, so normalize before comparing.
Related terms
- Unix timestamp — A Unix timestamp is the number of seconds that have passed since 00:00:00 UTC on 1 January 1970, the Unix epoch. It is a single number that identifies a moment in time regardless of time zone, which makes it easy to store, sort and compare.
- SHA-256 (Secure Hash Algorithm, 256-bit) — SHA-256 is a cryptographic hash function from the SHA-2 family that turns any input into a fixed 256-bit digest, usually written as 64 hexadecimal characters. The same input always gives the same output, and it is infeasible to work backwards from the digest.
References
Ads on this page
Non-personalized ads help keep Vaultools free — Google decides where they appear on the page.
Go Pro to remove them →