Skip to content

Generate Random UUID

Generate up to 1,000 UUIDs at once: random version 4, or time-ordered version 7 for database keys. Copy them as standard, uppercase, unhyphenated, URN or 22-character Base64url text, and paste any UUID to see its version, variant and embedded timestamp.

RFC 9562 · generated in your browser with crypto.getRandomValues()

Changing the format rewrites the same UUIDs

    Anatomy of a Version 4 UUID

    A UUID is 128 bits written as 32 hex digits in five groups of 8-4-4-4-12, 36 characters with hyphens. In a version 4 UUID, 6 of those bits are fixed and the other 122 are random:

    9b2e7c1a-4f3d-4a6b-8c2e-5d7f9a1b3c4e
    Fixed and random parts of a version 4 UUID
    PositionBitsValueMeaning
    13th hex digit (start of group 3)44Version: always 4 for random UUIDs
    17th hex digit (start of group 4)2 of its 48, 9, a or bVariant: the RFC 9562 layout
    Everything else122Random5.3 × 10³⁶ possible values

    That gives a quick sanity check: a v4 UUID always has a 4 after the second hyphen and 8, 9, a or b after the third. If yours don't, the value was made by something else, or by a homemade generator that skipped the version bits.

    UUID Versions 1 to 8 at a Glance

    UUID versions defined in RFC 9562
    VersionBuilt fromUse it for
    1Timestamp (100 ns since 1582) + node ID, often the MAC addressLegacy systems; reveals when and where it was made
    2DCE security: time + local user or group IDAlmost never used
    3MD5 hash of a namespace + nameThe same name always gives the same UUID; prefer v5
    4122 random bitsThe default for IDs, tokens and test data
    5SHA-1 hash of a namespace + nameStable IDs derived from URLs or names
    6Version 1's timestamp reordered so it sortsUpgrading v1 systems
    748-bit Unix time in ms + 74 random bitsDatabase primary keys that sort by creation time
    8Vendor-defined layoutCustom schemes

    RFC 9562 (May 2024) replaced RFC 4122 and added versions 6, 7 and 8. Microsoft calls UUIDs GUIDs; for .NET formats, byte order and SQL Server sorting, see the GUID generator.

    How Likely Is a Duplicate?

    With 2¹²² possible v4 UUIDs, the birthday approximation gives the chance of at least one duplicate among n UUIDs:

    P(duplicate) ≈ n² ÷ (2 × 2¹²²)
    Chance of at least one duplicate among n random version 4 UUIDs
    UUIDs generatedChance of any duplicate
    1 million9.4 × 10⁻²⁶
    1 billion9.4 × 10⁻²⁰
    1 trillion9.4 × 10⁻¹⁴
    1 quadrillion9.4 × 10⁻⁸
    2.7 × 10¹⁸50%

    Reaching even odds would take generating a billion UUIDs every second for about 86 years. In practice, duplicates come from bugs, not chance: a generator using a weak or badly seeded random source, a cloned VM restarting with the same state, or code that copies an ID instead of creating one. Use a secure generator (as this page and crypto.randomUUID() do) and still put a unique constraint on the column.

    Worked Example: Reading the Time Inside a v7 UUID

    A support engineer sees the order ID 01a13498-edc0-7b2d-9e1f-0a2b3c4d5e6f in a log and wants to know when the order was created.

    Step 1: Confirm the version

    13th digit is 7 → version 7; 17th digit is 9 → standard variant

    Step 2: Take the first 12 hex digits

    01a13498edc0 (hex) = 1,791,883,800,000 (decimal)

    Step 3: Read it as Unix milliseconds

    1,791,883,800,000 ms = 2026-10-13T09:30:00.000Z

    This is why v7 UUIDs sort by time, and also why they leak it: anyone who sees the ID can tell when the record was made. Use v4 for IDs shown to customers when creation time is sensitive. The inspector below does these steps for any v1, v6 or v7 UUID.

    Storing UUIDs: Text, Binary and Base64url

    Ways to store or transmit a UUID and their sizes
    FormSizeNotes
    Standard text36 charactersReadable; what APIs and JSON usually carry
    Hex without hyphens32 charactersFile names, some legacy columns
    Binary16 bytesPostgreSQL's uuid type; BINARY(16) elsewhere. Smallest and fastest to index
    Base64url22 charactersShort and URL-safe, e.g. in links
    URN45 charactersurn:uuid:… where a URI is required, as in XML namespaces

    RFC 9562 accepts upper, lower or mixed case, so compare UUIDs case-insensitively, or normalise to lowercase before storing text. A text column holding UUIDs takes more than twice the space of a native 16-byte type, and every index on it grows too.

    For primary keys, random v4 values land all over a B-tree index, which hurts insert speed on big tables. Version 7 values arrive in order and append near the end of the index instead. PostgreSQL 18 added uuidv7() for exactly this.

    Generating UUIDs in Code and Databases

    // JavaScript (browsers on HTTPS, Node 19+)
    crypto.randomUUID()                      // v4
    
    # Python
    import uuid
    uuid.uuid4()                             # v4
    uuid.uuid7()                             # v7, Python 3.14+
    
    -- PostgreSQL
    SELECT gen_random_uuid();                -- v4 (13+)
    SELECT uuidv7();                         -- v7 (18+)
    
    // Java
    java.util.UUID.randomUUID()              // v4
    
    # Linux / macOS shell
    uuidgen

    crypto.randomUUID() only exists on secure (HTTPS or localhost) pages. Avoid homemade generators built on Math.random(): their output is predictable and far more likely to repeat.

    Inspect a UUID

    Paste a UUID with or without hyphens, braces or a urn:uuid: prefix. For versions 1, 6 and 7 the creation time is decoded; try the RFC's own v1 example, f81d4fae-7dec-11d0-a765-00a0c91e6bf6, made on 3 February 1997.

    Details of the pasted UUID
    FieldValue
    Version7: Unix time + random
    Variant9 → RFC 9562 (standard)
    Created2026-10-13T09:30:00.000Z
    Random bits74
    Standard form01a13498-edc0-7b2d-9e1f-0a2b3c4d5e6f
    Base64urlAaE0mO3Aey2eHworPE1ebw

    Frequently asked questions

    Should I use UUID v4 or v7?

    v7 for database primary keys and anything you want sorted by creation time; v4 when the ID shouldn’t reveal when it was made, or when order doesn’t matter.

    Can a UUID be used as a password or secret link?

    A v4 UUID has 122 random bits, so it is hard to guess, but IDs are logged, shared and shown in URLs. Use a purpose-made token for secrets, and check access rights rather than relying on an unguessable ID.

    Are UUIDs case-sensitive?

    No. RFC 9562 allows upper, lower or mixed case, and they all mean the same value. Lowercase is the common convention.

    What is the nil UUID?

    00000000-0000-0000-0000-000000000000, all zeros. It means “no UUID” and often shows up when a field was never filled in. The max UUID, all f’s, is its counterpart.

    Sources