If you’ve worked with UUIDs, you’ve probably seen strings like this:
550e8400-e29b-41d4-a716-446655440000
That’s 36 characters long. So, is a UUID always 36 characters?
Let’s break it down.
🔢 The Standard UUID Format
UUIDs are 128-bit values, which equals 16 bytes of raw data. But they’re often displayed in a textual format for readability and interoperability.
The common string representation is:
- 32 hexadecimal digits
- 4 hyphens separating 5 groups
Example:
550e8400-e29b-41d4-a716-446655440000
That’s 36 characters total:
- 32 hex characters
- 4 hyphens
This is the canonical representation defined in [RFC 4122](https://datatracker.ietf.org/doc/html/rfc4122).
✂️ What If You Remove the Hyphens?
Just the raw hex value is 32 characters long:
550e8400e29b41d4a716446655440000
Same UUID, just formatted differently.
🧪 Python example:
import uuid
u = uuid.uuid4()
print(str(u)) # 36 characters (with hyphens)
print(u.hex) # 32 characters (no hyphens)
💾 Binary and Base64 Encodings
Remember, UUIDs are fundamentally 128-bit (16-byte) values. Depending on how they’re stored or transmitted, they might be:
- 16 bytes in binary form
- 22 characters in Base64 (URL-safe)
- 36 characters in standard string form
This has implications for storage, especially in databases or URL design.
Example:
import base64
u = uuid.uuid4()
base64_url = base64.urlsafe_b64encode(u.bytes).rstrip(b'=')
print(base64_url.decode()) # ~22 chars, URL-safe
🧠 Why Does This Matter?
While UUIDs are universally 128 bits in structure, how they're represented can affect:
- Storage efficiency (e.g. databases)
- URL readability
- API design
Don’t assume a UUID will always be 36 characters—only the canonical string version is.
✅ Final Thoughts
- UUIDs are 128-bit identifiers
- Standard string form = 36 characters
- Raw hex = 32 characters
- Encoded forms like Base64 = ~22 characters
So next time someone asks “Is a UUID always 36 characters?” you can confidently say:
“Only when printed as a standard string—with hyphens.”
Want to see how different UUID formats affect database indexing or network payload size? Stay tuned for our upcoming article on UUID performance tips!