The canonical format
A UUID in canonical string form is exactly 36 characters:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Breakdown:
| Group | Characters | Bits | Description |
|---|---|---|---|
| 1 | 8 hex | 32 | time_low or random |
- | 1 | — | separator |
| 2 | 4 hex | 16 | time_mid or random |
- | 1 | — | separator |
| 3 | 4 hex | 16 | version (1st char) + time_hi/rand |
- | 1 | — | separator |
| 4 | 4 hex | 16 | variant (1st char) + clock_seq/rand |
- | 1 | — | separator |
| 5 | 12 hex | 48 | node 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)
- Position 14 (first char of group 3): version nibble —
7means UUID v7 - Position 19 (first char of group 4): variant — must be
8,9,a, orbfor RFC 9562 UUIDs
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
| Format | Characters | Use case |
|---|---|---|
| Canonical (8-4-4-4-12) | 36 | Standard, human-readable |
| Compact (no hyphens) | 32 | URLs, JWT, compact storage |
| Base64url | 22 | Maximum URL compactness |
| Base58 | ~22 | Alphanumeric, no ambiguous chars |
| URN | 45 | Formal namespace identification |
See UUID URL-Safe Encoding and Base62 Encoding.
Related terms
- UUID Bit Fields — Version and Variant
- Variant — RFC 9562 identifier bits
- Version — UUID version nibble
- Base62 Encoding — compact UUID representation
- UUID URL-Safe 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.