Developer Utilities 5 min read Oct 07, 2026 FormatKit Engineering 6 views

Understanding UUIDs: Differences Between v1, v4, and v5

Explore Universally Unique Identifiers (RFC 4122). Learn why UUIDv4 is best for distributed IDs and how UUIDv7 improves database B-tree index performance.
Quick Answer • Key Takeaway
Use UUIDv4 for general-purpose applications: it provides 122 bits of cryptographic randomness with virtually zero chance of collision. Use UUIDv7 (or v1) when inserting IDs into relational database primary keys, because time-ordered sorting prevents B-tree page fragmentation.
Guide Sections

What is a UUID?

A UUID (Universally Unique Identifier), standardized in RFC 4122, is a 128-bit number formatted as 32 hexadecimal digits displayed in five hyphen-separated groups:

f47ac10b-58cc-4372-a567-0e02b2c3d479
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx

In the template above, M represents the UUID version (1 through 8) and N specifies the variant (typically 8, 9, a, or b for RFC 4122).

UUID Version Comparison

Version Generation Method Best For
UUID v1 Timestamp + Host MAC Address Time-ordered generation (reveals hardware MAC)
UUID v4 Cryptographically secure pseudo-random bits General-purpose distributed unique IDs
UUID v5 SHA-1 hash of a namespace + string Deterministic IDs derived from URLs or names
UUID v7 Unix epoch timestamp (ms) + random bits Database primary keys (B-tree index friendly)

Generate High-Entropy UUIDs Online

Create single or bulk RFC-compliant UUIDv4 identifiers instantly with copy and lowercase/uppercase toggles.

UUID Generator →

The Database Primary Key Penalty of UUIDv4

While UUIDv4 is excellent for distributed systems, using it directly as a clustered primary key in MySQL InnoDB or PostgreSQL causes performance degradation over time:

  • Index Fragmentation: Because UUIDv4 is completely random, new inserts are scattered randomly across disk pages, causing expensive B-tree rebalances.
  • Larger Index Size: A 128-bit UUID stored as a 36-character string takes 36 bytes per row, compared to 8 bytes for a BIGINT.

Frequently Asked Questions

Can UUIDv1 be a security liability?
Yes. Because UUIDv1 encodes your network card's physical MAC address and an exact microsecond timestamp, malicious actors can determine the physical machine and exact time of creation.
How can I generate a UUIDv4 natively in modern browsers?
Modern browsers support the Web Cryptography API: call crypto.randomUUID() to get a compliant RFC 4122 v4 UUID string instantly.
On This Page
100% In-Browser Privacy

FormatKit tools and interactive code examples run completely in your client browser sandbox. We never store, log, or transmit your code, tokens, or confidential API payloads.