What is Base64?
Base64 is an encoding scheme that converts binary data into a string of printable ASCII characters. It uses an alphabet of 64 characters — A–Z, a–z, 0–9, plus + and / — to represent any sequence of bytes as readable text.
The name comes directly from that alphabet size: 64 symbols, each representing 6 bits of data. It was standardized in RFC 4648 and is used everywhere binary data needs to travel through a text-only channel.
How it works
Base64 processes input in chunks of 3 bytes (24 bits). Each chunk is split into 4 groups of 6 bits. Each 6-bit group maps to one character in the Base64 alphabet:
01001101a
01100001n
01101110
T010110
W000101
F101110
u
So Man (3 bytes) encodes to TWFu (4 chars). Every 3 input bytes produce 4 output characters — a 33% size overhead.
Padding
When the input length is not a multiple of 3, Base64 adds = padding characters to make the output length a multiple of 4:
"Ma" (2 bytes) → "TWE=" (1 padding char) "M" (1 byte) → "TQ==" (2 padding chars) "Man" (3 bytes) → "TWFu" (no padding)Common use cases
- Data URIs — embed images directly in HTML or CSS without a separate file request:
src="data:image/png;base64,iVBOR..." - Email attachments (MIME) — email protocols were designed for 7-bit ASCII. Base64 encodes binary attachments so they survive transit.
- JSON payloads — JSON only supports text. Binary data (images, files, keys) must be Base64-encoded before being included in a JSON field.
- HTTP Basic Auth — credentials are sent as
Authorization: Basic base64(user:password). - JWT tokens — each part of a JWT (header, payload, signature) is Base64url-encoded (a URL-safe variant).
- Cryptographic keys — PEM files (.pem, .crt) store keys and certificates as Base64-encoded DER data.
Base64 vs Base64url
Standard Base64 uses + and / characters that have special meanings in URLs, requiring percent-encoding. Base64url is a URL-safe variant that solves this:
A–Z a–z 0–9 + /=A–Z a–z 0–9 - _What Base64 is NOT
Base64 is purely a representation format — it makes binary data safe to handle in text contexts. Nothing more.