How to convert UUID to Base64 - cover art

How-to guides 11 min read

How to convert UUID to Base64

August 7, 2026 · 11 min read

APIs and databases sometimes store a UUID as 16 raw bytes encoded in Base64 instead of the familiar hyphenated hex string. JWT claims, MongoDB exports, and compact URL parameters all use this shape. Converting correctly means parsing the canonical UUID to bytes first - not Base64-encoding the ASCII text of the string.

Why Base64 UUIDs appear

A canonical UUID is 36 characters UTF-8; the binary form is 16 bytes. Base64 expands binary to roughly 22–24 characters without hyphens, which fits binary-safe columns and URL paths when configured for URL-safe alphabets.

Conversion steps

// Conceptual: 16 bytes ↔ Base64 (use a tested library in production)
const hex = "550e8400-e29b-41d4-a716-446655440000";
const bytes = uuidStringToBytes(hex);
const b64 = btoa(String.fromCharCode(...bytes));

Base64 vs Base64URL

JWT and many web APIs use Base64URL: - and _ instead of + and /, padding often stripped. Mixing alphabets produces valid-looking but wrong IDs when decoded.

Using the UUID converter

The UUID converter on UUID Studio accepts canonical UUIDs, hex, and Base64/Base64URL in the browser. Paste a value, switch representation, and copy the result - useful when a log line shows Base64 but your ORM expects hyphenated strings.

Common pitfalls

Encoding the 36-character string as UTF-8 Base64 is wrong - you will get 48 bytes of ASCII, not 16 bytes of identity. Always convert through binary UUID octets. Watch MongoDB subtype 03 vs 04 byte order when importing from .NET GUIDs.

FAQ

How long is a UUID in Base64?
16 bytes encode to 24 Base64 characters with padding, or 22 without padding depending on encoding options.
Is Base64URL the same as Base64 for UUIDs?
Same bits, different alphabet and padding rules. Always know which alphabet your API expects.

Related: What is a UUID · UUID converter

Browse all tools