Base64 encoding
What Base64 is, why it exists, how it works, and the cases where it is the wrong tool.
What Base64 is
Base64 is a way to represent arbitrary binary data using only 64 printable ASCII characters (AβZ, aβz, 0β9, + and /, with = for padding). It is an encoding, not encryption: anyone can decode it, and it provides no confidentiality or integrity.
It was designed for a world where data had to travel through systems built for plain text β email (SMTP), early Usenet, and various configuration formats β that might mangle control characters or 8-bit bytes.
Man β TWFu
M a n
01001101 01100001 01101110 (3 bytes / 24 bits)
|||||||| |||||||| ||||||||
T W F u (split into four 6-bit groups β 4 Base64 chars)How the encoding works
Base64 groups the input into 3-byte (24-bit) chunks, then splits each chunk into four 6-bit values. Each 6-bit value (0β63) maps to one character in the alphabet. If the final chunk has only 1 or 2 bytes, it is zero-padded and the output is padded with one or two = signs.
- 3 input bytes β exactly 4 output characters (no padding).
- 2 input bytes β 3 characters + one
=pad. - 1 input byte β 2 characters + two
=pads.
Where you actually see it
- Data URLs in CSS/HTML:
data:image/png;base64,iVBORw0β¦embeds a small image inline. - HTTP:
Basicauth sendsAuthorization: Basic base64(user:pass)(over TLS only!). - JSON / APIs: binary blobs (files, keys) are often Base64-encoded before being placed in a text field.
- Certificates & keys: PEM files are Base64-wrapped DER with
-----BEGINβ¦-----headers. - Email attachments: MIME
Content-Transfer-Encoding: base64.
Common variants
| Variant | Difference |
|---|---|
| Standard | Alphabet +/, pad =. |
| URL-safe | Uses -_ instead of +/ so it is safe in URLs/paths (no padding issues). |
| Base32 / Base58 | Used where case-insensitivity or human-typing matters (e.g. Bitcoin addresses use Base58). |
FAQ
Is Base64 encryption?
Why is my Base64 string padded with =?
How much bigger does my data get?
Related
URL encoding (percent-encoding) UTF-8 and character sets Checksums & verifying files
Last refreshed 2026-09-17.