What is a UUID?
4 min read · Identifiers
The short answer
A UUID (Universally Unique Identifier) is a 128-bit number used to uniquely identify information in computer systems. UUIDs are designed to be unique across all space and time — you can generate one on your laptop right now and be virtually certain no one else has ever generated the same value.
A UUID looks like this:
550e8400-e29b-41d4-a716-446655440000
It is 32 hexadecimal characters arranged in 5 groups separated by hyphens: 8-4-4-4-12.
UUID versions
UUID v1 — Time-based
Generated from the current timestamp and the machine's MAC address. Guaranteed to be unique but reveals when and where it was created — a potential privacy concern.
UUID v4 — Random ★ Most popular
Generated from random numbers. No timestamp, no machine info. The probability of generating two identical v4 UUIDs is astronomically small. This is what most developers use.
UUID v5 — Name-based (SHA-1)
Generated deterministically from a namespace and a name. The same inputs always produce the same UUID. Useful when you need a stable ID for a known value (e.g., a URL or email address).
UUID v7 — Time-ordered random
A newer format that combines a millisecond timestamp with random bits. Sortable by creation time, making it much better for database primary keys than v4.
Why use UUIDs?
- No central coordination needed — any client can generate an ID without asking a server
- No sequential IDs exposed — auto-increment IDs like 1, 2, 3 reveal how many records you have and make enumeration attacks easy
- Works across distributed systems — multiple databases or services can generate IDs independently without collisions
- Safe to expose publicly — UUIDs in URLs do not reveal business information
UUID vs auto-increment IDs
| UUID | Auto-increment | |
|---|---|---|
| Readability | Hard to read | Easy (1, 2, 3...) |
| Security | Safe to expose | Reveals record count |
| Distribution | Fully distributed | Requires central DB |
| DB index performance | Worse (v4), Good (v7) | Excellent |
| Storage | 16 bytes | 4–8 bytes |
Generating UUIDs in code
In JavaScript/TypeScript (modern browsers and Node.js 14.17+):
const id = crypto.randomUUID(); // "550e8400-e29b-41d4-a716-446655440000"
In Python:
import uuid id = str(uuid.uuid4()) # "550e8400-e29b-41d4-a716-446655440000"
In Go:
import "github.com/google/uuid" id := uuid.New().String()
Storing UUIDs in databases
Most databases have a native UUID type. Use it — it stores UUIDs more efficiently than a plain VARCHAR(36).
- PostgreSQL:
UUIDcolumn type - MySQL:
CHAR(36)orBINARY(16)for efficiency - MongoDB: Use
BinDatasubtype 4 - SQLite:
TEXT(no native UUID type)
If database index performance is critical, prefer UUID v7 over v4 — its time-ordered structure means new records are always inserted at the end of the index, avoiding costly page splits.
Generate UUIDs instantly
Generate single or bulk UUIDs (v1, v4) right in your browser — no installation needed.
UUID Generator →