How Base64 Works

Base64 is an encoding scheme that represents binary data as printable ASCII characters. It is not encryption — it is a way to safely transport binary data through text-only channels.

Why Base64 Exists

Many protocols (email, HTTP headers, JSON, URLs) were designed to carry text, not arbitrary binary. Attaching a JPEG directly to an email would corrupt it — Base64 solves this by encoding the binary as text.

How It Works

Base64 takes 3 bytes (24 bits) at a time and splits them into four 6-bit groups. Each 6-bit value (0–63) maps to a printable character from the Base64 alphabet: A-Z (0-25), a-z (26-51), 0-9 (52-61), + (62), / (63).

Padding

If the input length isn't a multiple of 3, "=" padding characters are appended. One "=" means 2 remaining bytes; "==" means 1 remaining byte. For example, "a" encodes to "YQ==".

Size Impact

Base64 increases data size by approximately 33% — every 3 bytes become 4 characters. This is the cost of making binary data text-safe.

URL-Safe Base64

Standard Base64 uses + and /, which are special in URLs. URL-safe Base64 (RFC 4648 §5) replaces + with - and / with _. JWTs (JSON Web Tokens) use URL-safe Base64.

Related Tools