Glossary

UUID (Universally Unique Identifier)

A 128-bit identifier standardized in RFC 9562, displayed as 32 hexadecimal digits in five hyphen-separated groups. UUIDs can be generated by any system without central coordination while maintaining practical uniqueness across distributed systems.

A UUID (Universally Unique Identifier) is a 128-bit identifier standardized in RFC 9562, represented as 32 hex digits in the format xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx. The version digit M identifies the generation algorithm. UUIDs can be generated independently by any machine without coordination, with collision probability so low (1 in 2^122 for UUID v4) it is treated as impossible in practice.

Versions

VersionAlgorithmUse Case
v1Timestamp + MAC addressDeprecated (leaks MAC address)
v3MD5 hash of nameDeterministic IDs (prefer v5)
v4RandomUnpredictable IDs, tokens
v5SHA-1 hash of nameDeterministic IDs from strings
v7Unix ms timestamp + randomDatabase primary keys

UUID v4 Example

f47ac10b-58cc-4372-a567-0e02b2c3d479
              ^    ^
              4    [89ab] — version 4 and variant markers

122 bits are random. The probability of generating two identical UUID v4 values is approximately 1 in 2^122.

UUID v7 for Databases

UUID v7 embeds a millisecond timestamp in the first 48 bits, making IDs chronologically sortable. This dramatically reduces B-tree index fragmentation and improves database insert performance compared to UUID v4.

01905b80-3e40-7abc-8def-123456789abc
^^^^^^^^ ^^^^
48-bit Unix ms timestamp

Database Storage

Store UUIDs as binary (16 bytes), not as VARCHAR(36):

-- PostgreSQL: native uuid type (16 bytes)
id uuid DEFAULT gen_random_uuid() PRIMARY KEY

-- MySQL: BINARY(16) is more efficient than VARCHAR(36)
id BINARY(16) DEFAULT (UUID_TO_BIN(UUID(), 1))

Generate UUIDs instantly with the UUID Generator Tool.