The Ultimate UUID Cheat Sheet for 2025

    February 17, 2025
    12 min read
    Reference
    Long read
    uuid
    best-practices
    tutorial

    🧾 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

    VersionDescriptionPropertiesUse Case
    v1Time + MAC addressOrdered, traceableLegacy systems, internal indexing
    v2DCE SecurityRare, POSIX-specificObsolete
    v3MD5-hash namespaceDeterministicStable namespacing
    v4Random-basedCollision-resistant, fastDefault for most apps
    v5SHA-1 namespaceDeterministic, secureVersioned naming
    v6Reordered v1Deprecated in favor of v7Time-ordered but not adopted
    v7Timestamp + randomnessSortable, secureLogging, analytics, ordering
    v8Custom layoutFlexible, experimentalCustom 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

    go
    import "github.com/google/uuid"
    
    uuid.New()         // v4
    uuid.NewMD5(...)   // v3
    uuid.NewSHA1(...)  // v5

    Python

    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)

    js
    import { v4, v5 } from 'uuid';
    
    v4(); // Random UUID
    v5('example.com', v5.DNS); // Name-based

    Rust

    rust
    use uuid::Uuid;
    
    Uuid::new_v4();
    Uuid::new_v5(&Uuid::NAMESPACE_DNS, b"example.com");

    Bash / CLI

    bash
    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

    bash
    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 or BINARY(16) over VARCHAR(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

    python
    import uuid, base58
    base58.b58encode(uuid.UUID("550e8400-e29b-41d4-a716-446655440000").bytes)

    UUID → Int

    python
    int(uuid.uuid4())

    📊 UUID Comparison Table

    Featurev1v3/v5v4v7v8
    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 utilities
    • hashids, 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 🧙‍♂️

    Generate Your Own UUIDs

    Ready to put this knowledge into practice? Try our UUID generators:

    Generate a Single UUID

    Create a UUID with our fast, secure generator

    Bulk UUID Generator

    Need multiple UUIDs? Generate them in bulk

    Summary

    This definitive 2025 UUID reference guide covers all versions (v1–v8), generation methods, formats, performance tips, and best practices. Ideal for developers building distributed systems, APIs, and scalable apps.

    TLDR;

    This cheat sheet is your one-stop reference for working with UUIDs in 2025.

    Key points to remember:

    • UUIDv4 is best for randomness; UUIDv7 for sortability; UUIDv8 for custom use
    • Be mindful of storage (UUIDs are 128-bit) and indexing implications
    • Avoid exposing UUIDv1 publicly due to privacy leaks

    Includes generation code samples, format differences, version comparison table, and top dos/don’ts for production-ready UUID handling.

    Cookie Consent

    We use cookies to enhance your experience on our website. By accepting, you agree to the use of cookies in accordance with our Privacy Policy.