🧾 The Ultimate UUID Cheat Sheet for 2025
UUIDs (Universally Unique Identifiers) are everywhere — from primary keys and session tokens to distributed object identifiers. This cheat sheet gives you the complete rundown on UUIDs, updated for 2025.
Use it to choose the right version, avoid common mistakes, and reference language-specific generation code.
🔢 UUID Versions Overview
Version | Description | Properties | Use Case |
---|---|---|---|
v1 | Time + MAC address | Ordered, traceable | Legacy systems, internal indexing |
v2 | DCE Security | Rare, POSIX-specific | Obsolete |
v3 | MD5-hash namespace | Deterministic | Stable namespacing |
v4 | Random-based | Collision-resistant, fast | Default for most apps |
v5 | SHA-1 namespace | Deterministic, secure | Versioned naming |
v6 | Reordered v1 | Deprecated in favor of v7 | Time-ordered but not adopted |
v7 | Timestamp + randomness | Sortable, secure | Logging, analytics, ordering |
v8 | Custom layout | Flexible, experimental | Custom IDs with embedded data |
🧪 Which UUID Version Should You Use?
- v4: For general purpose IDs (users, sessions, etc.)
- v7: For log/event ordering, Kafka, time-indexed stores
- v5: For generating same ID from name + namespace (e.g. DNS)
- v8: For internal IDs with custom fields (e.g. tenant, region)
⚙️ UUID Generation Techniques by Language
Go
import "github.com/google/uuid"
uuid.New() // v4
uuid.NewMD5(...) // v3
uuid.NewSHA1(...) // v5
Python
import uuid
uuid.uuid4() # Random
uuid.uuid1() # Time + MAC
uuid.uuid3(uuid.NAMESPACE_DNS, "example.com")
uuid.uuid5(uuid.NAMESPACE_DNS, "example.com")
JavaScript (Node.js)
import { v4, v5 } from 'uuid';
v4(); // Random UUID
v5('example.com', v5.DNS); // Name-based
Rust
use uuid::Uuid;
Uuid::new_v4();
Uuid::new_v5(&Uuid::NAMESPACE_DNS, b"example.com");
Bash / CLI
uuidgen # Default v4 or v1 (OS dependent)
uuid -v # See version if supported
🔍 UUID Format & Encoding
- Hex format:
550e8400-e29b-41d4-a716-446655440000
- Bytes (binary): 16 bytes (128 bits)
- Base36: Shorter, alphanumeric (for URLs)
- Base58/Base62: Compact, URL-safe alternatives
- Multibase (e.g., IPFS): Includes prefix for encoding type
Example: UUID in base58
pip install base58
python -c "import uuid, base58; print(base58.b58encode(uuid.uuid4().bytes))"
🧠 UUID Design Best Practices
✅ DO:
- Use UUIDv4 for simple, secure, random IDs
- Use UUIDv7 when order matters (timestamps)
- Use UUIDv5 when deriving IDs from names
- Store UUIDs in binary (BINARY(16)) in MySQL/Postgres for performance
- Index UUID columns properly (especially with non-sequential types)
❌ DON’T:
- Don’t use UUIDv1 in public-facing contexts (leaks MAC, timestamp)
- Don’t use UUIDs as primary index if write amplification matters (v4 causes fragmentation)
- Don’t truncate UUIDs — you’ll lose uniqueness guarantee
⚖️ UUID Performance and Storage
- Size: 128-bit = 16 bytes
- MySQL/Postgres: Prefer
UUID
orBINARY(16)
overVARCHAR(36)
- MongoDB: Use
BinData
type - Redis: UUIDs used as string keys
Indexing Tips
- Avoid using UUIDv4 as clustered primary key
- Consider sequential-friendly formats (e.g., UUIDv7, KSUID, ULID)
- Batch inserts to reduce random I/O
🔐 UUID Security Tips
- UUIDs are not cryptographic tokens (unless generated securely)
- Use UUIDv4 from a CSPRNG (not
Math.random
) - Don’t encode sensitive info (e.g., email, PII) in UUIDv8 without encryption
- For signed/secure IDs, look at JWKs, JWTs, or DIDs
🔄 UUID Conversion Cheats
Hex → Base58
import uuid, base58
base58.b58encode(uuid.UUID("550e8400-e29b-41d4-a716-446655440000").bytes)
UUID → Int
int(uuid.uuid4())
📊 UUID Comparison Table
Feature | v1 | v3/v5 | v4 | v7 | v8 |
---|---|---|---|---|---|
Ordered | ✅ | ❌ | ❌ | ✅ | ✅* |
Deterministic | ❌ | ✅ | ❌ | ❌ | ✅* |
Privacy-Safe | ❌ | ✅ | ✅ | ✅ | ✅ |
Sortable | ❌ | ❌ | ❌ | ✅ | ✅* |
Custom Payload | ❌ | ❌ | ❌ | ❌ | ✅ |
RFC Standard | ✅ | ✅ | ✅ | ✅ | ✅ |
*UUIDv8 allows you to define all of the above yourself — just be careful.
🚀 UUID Alternatives to Know
- ULID: Time-sorted + random (base32)
- KSUID: Sortable, secure IDs with timestamp
- Snowflake: Compact, sortable (used by Twitter, Discord)
- CIDs: Content-addressable hashes (IPFS)
- DIDs: Decentralized identity identifiers (W3C)
📚 Helpful Tools and Libraries
- [uuidtools.com](https://www.uuidtools.com) – generate + inspect UUIDs
- [uuid.online](https://uuid.online) – decode/encode viewer
uuid-cli
,uuidgen
– CLI utilitieshashids
,shortuuid
,base62
– alternatives for compact IDs
🧩 When Not to Use UUIDs
- When you need incrementing values for analytics
- When you can guarantee central coordination (e.g. Snowflake IDs)
- When you need cryptographic integrity or traceability → use CIDs/DIDs
Final Thoughts
Whether you’re just generating IDs for new users or designing the next globally distributed database, choosing the right UUID version and implementation matters.
UUIDs are simple — but not trivial. Understanding their trade-offs in performance, storage, privacy, and interoperability will help you build more scalable and resilient systems.
Keep this cheat sheet bookmarked, and you’ll be the UUID wizard on your team 🧙♂️