UUID UUID Generator

Free · No signup · No install

How Long Is a UUID?

36 characters when you paste it, 32 hex digits when the hyphens go away, 16 bytes in the database and 128 bits underneath. Here is where each number comes from — and which ones you can shrink.

  • 36 chars canonical
  • 32 hex digits
  • 128 bits of data

UUID v4 Generator

v4
Between 1 and 1000.
Formatting

Result 0

    Generated locally with the Web Crypto API — nothing leaves your browser. Shortcut: Ctrl + Enter — Regenerated

    What is a How Long Is a UUID?

    A UUID is a 128-bit value. Written the canonical way it becomes 36 characters: five groups of 8, 4, 4, 4 and 12 hexadecimal digits separated by four hyphens. Remove the hyphens and you have 32 characters, which is exactly 32 × 4 bits = 128 bits with nothing lost or added.

    Stored natively it is 16 bytes — PostgreSQL's uuid, SQL Server's uniqueidentifier, MySQL's BINARY(16). That is the form to prefer: it is less than half the size of the text form and compares much faster, because the database can compare 16 bytes instead of parsing a 36-character string.

    Not all 128 bits are payload. Six of them are structure: four bits record the version and two record the variant, leaving 122 random bits in a v4 UUID. That is still an enormous space — 5.3 × 1036 possible values — but it explains why the entropy of a v4 is quoted as 122 and not 128.

    How to

    1. Copy the canonical 36-character form for humans, docs and configuration files.
    2. Drop the hyphens for logs, compact keys and anything that has to fit a fixed width.
    3. Store 16 bytes natively when the column is indexed, and read the length breakdown below when someone asks why a UUID is not 128 characters long.

    Use cases

    • Column sizing: CHAR(36) versus a native 16-byte type — the difference decides your index size.
    • Fixed-width logs, where you need to know whether a field is 32 or 36 characters before you write a parser.
    • UI decisions: knowing a v4 is 36 characters tells you whether to truncate it in a table cell or show it in full.

    Compare How Long Is a UUID? with other formats

    OptionWhen to use
    36 charactersCanonical <code>8-4-4-4-12</code> with hyphens. What you see and copy.
    32 charactersThe same value with hyphens removed; still 128 bits.
    16 bytesNative storage in a <code>uuid</code>, <code>uniqueidentifier</code> or <code>BINARY(16)</code> column.
    22 charactersBase64url — the same 16 bytes, the shortest lossless text form.
    128 bitsThe payload: 122 random bits in v4, plus 6 for version and variant.

    Code examples

    Measuring the length in code

    import uuid
    
    u = uuid.uuid4()
    len(str(u))      # 36
    len(u.hex)       # 32
    len(u.bytes)     # 16, bytes
    u.int            # the 128-bit integer value
    
    # Base64url is the shortest lossless text form
    import base64
    len(base64.urlsafe_b64encode(u.bytes).rstrip(b'='))   # 22

    Sizing a column

    -- PostgreSQL: native type, 16 bytes on disk
    CREATE TABLE items (id uuid PRIMARY KEY DEFAULT gen_random_uuid());
    
    -- MySQL: BINARY(16) instead of CHAR(36)
    CREATE TABLE items (id BINARY(16) PRIMARY KEY);
    
    -- SQL Server: UNIQUEIDENTIFIER instead of VARCHAR(36)
    CREATE TABLE items (id UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID());

    Shortening a UUID

    // 36 characters -> 22, with no loss at all
    const hex = '550e8400e29b41d4a716446655440000';
    const b64 = Buffer.from(hex, 'hex').toString('base64url');
    console.log(b64.length);   // 22

    Frequently asked questions

    Why is a UUID 36 characters and not 32?

    Because the hyphens are added for readability. Four separators turn 32 hex digits into five groups, which is much easier to scan and to proofread. The underlying value is 32 hex digits; remove the hyphens and nothing changes except the notation.

    How many characters is a GUID?

    The same 36 in its default D form. .NET adds other spellings: N is 32 characters without hyphens, B is 38 with braces, P is 38 with parentheses, and X is 68 because each byte is written with a 0x prefix.

    Can I make a UUID shorter?

    Yes, in one of two ways. Lossless: encode the same 16 bytes as base64url and you get 22 characters, and it converts back exactly. Lossy: drop bytes — 12 bytes gives 16 characters and 96 bits of entropy, 8 bytes gives 11 characters and 64 bits — which is fine for caches but weak for permanent keys.