consolelog.tools
RFC 9562 reference

UUID versions and format, on one page

A UUID is a 128-bit identifier written as 36 characters of hex — 8-4-4-4-12 — designed to be generated anywhere, by anyone, without coordination and without collisions. Eight versions exist; only three matter day to day: v4 (pure random, the default everywhere), v7 (time-sortable, the modern pick for database keys), and v5 (deterministic, hashed from a name).

This page is the reference: the format, annotated, the version table, generation snippets for JavaScript, SQL, Python, and the terminal, and the collision math. To mint UUIDs in bulk — any version, uppercase, braced, or raw bytes — use the UUID generator; for the full v4-vs-v7 decision, read UUID v4 vs v7.

The format, annotated

Every standard UUID fixes six bits: the version nibble (13th hex digit) says how it was made, and the variant nibble (17th digit, always 8, 9, a, or b) marks it as an RFC-form UUID. Everything else is payload — random bits, timestamp, or hash, depending on the version.

anatomy of a UUID
                    version nibble (here: 4)
                          │
  0195c2f0-8f3a-4d6e-b81f-3c92a54d7e19
  └──┬───┘ └─┬─┘ └─┬─┘ └┬─┘ └────┬────┘
   8 hex   4 hex  4 hex │     12 hex        = 32 hex digits, 128 bits
                        │
              variant nibble (8, 9, a, or b)

All UUID versions at a glance

RFC 9562 (2024) superseded RFC 4122 and added v6, v7, and v8. Version 2 is omitted below — it was a DCE security variant that effectively nobody generates today.

VersionBuilt fromWhen to use it
v160-bit Gregorian timestamp + clock sequence + MAC addressLegacy. Time-ordered but leaks the host MAC and creation time; superseded by v6/v7.
v3MD5 hash of a namespace UUID + a nameDeterministic IDs from names. Prefer v5 — same idea, SHA-1 instead of MD5.
v4122 random bits (6 bits fixed for version + variant)The default everywhere. What crypto.randomUUID(), Python uuid4(), and Postgres gen_random_uuid() produce.
v5SHA-1 hash of a namespace UUID + a nameDeterministic: the same namespace + name always yields the same UUID. Good for stable IDs derived from URLs or emails.
v6v1 fields reordered so timestamp bits leadA sortable drop-in for systems already storing v1. New systems should pick v7 instead.
v748-bit Unix millisecond timestamp + 74 random bitsThe modern choice for database keys: time-sortable, index-friendly, no MAC leak. Standardized in RFC 9562 (2024).
v8122 bits of application-defined layoutAn escape hatch: format-compliant but the content is entirely yours. Use only when v4/v7 genuinely cannot express what you need.

Deciding between the two that matter? UUID v4 vs v7 covers index locality, timestamp leakage, and migration in depth.

Generate a UUID anywhere

JavaScript / TypeScript (browser + Node 16.7+) — v4
crypto.randomUUID()
// "0195c2f0-8f3a-4d6e-b81f-3c92a54d7e19"
// Built in, cryptographically random. Browsers require a secure
// context (https or localhost). For v7 use the uuid package:
import { v7 as uuidv7 } from 'uuid';   // npm i uuid
Terminal (macOS / Linux)
uuidgen                                  # macOS & util-linux, v4
cat /proc/sys/kernel/random/uuid         # Linux kernel, v4
python3 -c "import uuid; print(uuid.uuid4())"
SQL
-- PostgreSQL (13+): built-in v4
SELECT gen_random_uuid();
-- PostgreSQL 18+: built-in, time-sortable v7
SELECT uuidv7();
-- MySQL: UUID() returns v1 (time + MAC) — use UUID_TO_BIN(UUID(), 1)
-- for index-friendly storage, or generate v4/v7 in the application.
Python
import uuid
uuid.uuid4()          # random v4
uuid.uuid5(uuid.NAMESPACE_URL, "https://example.com")  # deterministic v5

How unique is a UUID, really?

A v4 UUID carries 122 random bits — about 5.3 × 10³⁶ possible values. The birthday bound says you would need roughly 2.7 × 10¹⁸ UUIDs — a billion per second for about 85 years — before the odds of even one collision reach 50%. Real-world collisions come from broken randomness (a seeded PRNG, cloned VM snapshots, a bad polyfill), never from the format itself. For v7, uniqueness within the same millisecond rests on its 74 random bits — still far beyond anything a single system generates.

UUID vs GUID vs ULID vs Nano ID

IdentifierShapeThe short version
GUIDIdentical to UUID — 128 bits, same formatJust Microsoft’s name for the same thing. .NET’s Guid.NewGuid() emits UUID v4.
ULID26 chars, Crockford base32, 48-bit timestamp + 80 random bitsSortable like UUID v7 with a more compact text form. Not an IETF standard; v7 is the standardized equivalent.
Nano ID21 URL-safe chars by default, ~126 bits of randomnessShorter, URL-friendly random IDs when you don’t need UUID’s fixed format — common for public-facing slugs.

Make IDs, right here

Frequently asked questions