The canonical format

A UUID in canonical string form is exactly 36 characters:

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Breakdown:

GroupCharactersBitsDescription
18 hex32time_low or random
-1—separator
24 hex16time_mid or random
-1—separator
34 hex16version (1st char) + time_hi/rand
-1—separator
44 hex16variant (1st char) + clock_seq/rand
-1—separator
512 hex48node or random

Total: 32 hex + 4 hyphens = 36 characters.

Reading the version and variant

018fbe3a-4c5d-7b12-8f3e-1a2b3c4d5e6f
              ↑         ↑
              version=7  variant=8 (binary: 1000 → top 2 bits = 10 = RFC 9562)

See UUID Bit Fields for the full bit layout.

Parsing and validation in code

// JavaScript — uuid package
import { validate, version, parse } from 'uuid';

const id = '018fbe3a-4c5d-7b12-8f3e-1a2b3c4d5e6f';

validate(id);        // true — valid UUID format
version(id);         // 7 — UUID v7

// Parse to Uint8Array (16 bytes)
const bytes = parse(id);

// Stringify bytes back to canonical form
import { stringify } from 'uuid';
const canonical = stringify(bytes); // lowercase, with hyphens
# Python — standard library
import uuid

id_str = '018fbe3a-4c5d-7b12-8f3e-1a2b3c4d5e6f'
u = uuid.UUID(id_str)

print(str(u))       # '018fbe3a-4c5d-7b12-8f3e-1a2b3c4d5e6f' (canonical)
print(u.hex)        # '018fbe3a4c5d7b128f3e1a2b3c4d5e6f' (no hyphens)
print(u.version)    # 7
print(u.bytes)      # b'\x01\x8f...' (16 bytes)

URN representation

RFC 9562 also defines a URN representation:

urn:uuid:018fbe3a-4c5d-7b12-8f3e-1a2b3c4d5e6f

The urn:uuid: prefix identifies the UUID URN namespace. Most APIs use the canonical string directly (without the URN prefix). See UUID URL-Safe Encoding for shorter alternatives to the 36-character format.

Case normalisation

// Always normalise to lowercase before storing
function normaliseUuid(id: string): string {
  return id.toLowerCase();
}

// Database: store lowercase, compare lowercase
// Never mix cases in the same column — it breaks index equality

Alternative representations

FormatCharactersUse case
Canonical (8-4-4-4-12)36Standard, human-readable
Compact (no hyphens)32URLs, JWT, compact storage
Base64url22Maximum URL compactness
Base58~22Alphanumeric, no ambiguous chars
URN45Formal namespace identification

See UUID URL-Safe Encoding and Base62 Encoding.

Frequently asked questions

What is the canonical UUID string format?

The canonical UUID string is 36 characters: 32 lowercase hexadecimal digits arranged in five groups separated by hyphens, in the pattern 8-4-4-4-12. Example: 018fbe3a-4c5d-7b12-8f3e-1a2b3c4d5e6f. RFC 9562 specifies that implementations should output lowercase and must accept both lowercase and uppercase. Hyphens are part of the format — a UUID without hyphens (32 hex chars) is not canonical but is widely accepted by parsers.

Are uppercase UUID strings valid?

Yes. RFC 9562 §4 states that UUID parsers must accept both uppercase and lowercase hex digits. However, the standard recommends outputting lowercase. Most libraries normalise to lowercase on output. When storing UUIDs, normalise to a consistent case — mixing cases in a database column prevents index equality matches.

What is a compact UUID (without hyphens)?

A compact UUID is the 32-character hex string with hyphens removed: 018fbe3a4c5d7b128f3e1a2b3c4d5e6f. This is not the canonical format but is widely used in URLs, JWT subjects, and systems where hyphens cause parsing issues. The uuid package provides uuid.replace(/-/g, '') for JavaScript. Compact UUIDs are not Base64 — they are still hex. See UUID URL-Safe Encoding for shorter alternatives.