What is Base64? Encoding Explained with Examples
Base64 encodes binary data as ASCII text so it can be safely transmitted over systems that only handle text. Learn how Base64 encoding works, why it exists, common use cases like data URIs and JWTs, and how to decode Base64 strings.
The one-sentence explanation
Base64 converts binary data (bytes) into a string of 64 printable characters so it can be safely embedded anywhere that only accepts plain text — email, JSON, HTML, URLs, and HTTP headers.
Why does Base64 exist?
Many older protocols and systems were designed for 7-bit ASCII text. Binary data (images, files, cryptographic keys) contains byte values that these systems interpret as control characters, causing corruption or truncation. Base64 sidesteps this by mapping every 3 bytes of binary data into 4 printable ASCII characters — none of which are control characters.
The 64 characters used are: A–Z, a–z, 0–9, +, / (with = as padding). URL-safe Base64 replaces + with - and / with _.
How encoding works
Base64 takes 3 bytes (24 bits) at a time and splits them into four 6-bit groups. Each 6-bit group maps to one of the 64 characters in the alphabet.
If the input length isn't divisible by 3, = padding characters are appended to make the output length a multiple of 4.
Common real-world uses
- Email attachments (MIME) — email was designed for 7-bit text. SMTP encodes attachments as Base64 so binary files survive transit.
- Data URIs in HTML/CSS — embed images directly in HTML without a separate HTTP request:
src="data:image/png;base64,iVBORw0KGgo..." - JSON Web Tokens (JWT) — a JWT is three Base64url-encoded sections separated by dots:
header.payload.signature. The payload is not encrypted — just encoded — so never put secrets in a JWT payload. - Basic HTTP authentication — the
Authorization: Basicheader sendsusername:passwordas Base64. - Cryptographic keys and certificates — PEM format (the
-----BEGIN CERTIFICATE-----files) is Base64-encoded DER binary.
Base64 is not encryption
Size overhead
Base64 output is always approximately 33% larger than the input (3 bytes become 4 characters). A 1 MB image becomes roughly 1.37 MB as Base64. This is the trade-off for text-safe transport.
Base64 vs hex encoding
| Property | Base64 | Hex |
|---|---|---|
| Characters used | 64 (A–Z, a–z, 0–9, +, /) | 16 (0–9, a–f) |
| Size overhead | ~33% | ~100% |
| URL safe? | ⚠ No (use Base64url) | ✓ Yes |
| Human readable? | No | Somewhat |
| Common for | Files, images, JWT, email | Hashes, byte dumps, colours |
Encode or decode Base64 instantly
Paste any text or Base64 string and convert in one click
Open Base64 Encoder →