Blog / Base64 Encoding Guide
Base64 Encoding Guide: How It Works & When to Use It
2026-06-25 · 8 min read
Advertisement
What Is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts binary data into a set of 64 printable ASCII characters. It is everywhere in modern computing - from embedding images in HTML and CSS, to encoding email attachments, to transmitting data in JSON APIs.
The name "Base64" comes from its alphabet of 64 characters: A-Z (26), a-z (26), 0-9 (10), plus "+" and "/" — exactly 64 symbols. The "=" character serves as padding when the input length is not divisible by 3.
How Base64 Encoding Works
Base64 encodes every 3 bytes (24 bits) of binary data into 4 ASCII characters (6 bits each, since 2^6 = 64):
- Step 1 - Take the input data and split it into 3-byte groups. Each byte is 8 bits, so a group is 24 bits.
- Step 2 - Divide the 24 bits into four 6-bit chunks. Each 6-bit value (0-63) maps to one Base64 character.
- Step 3 - If the last group has fewer than 3 bytes, add zero bits and use "=" padding.
For example, the text Man encodes to TWFu. This deterministic process makes decoding equally straightforward.
Where You See Base64 Every Day
- Data URIs in HTML/CSS - Small images embedded as Base64 strings:
data:image/png;base64,iVBORw0KG... - Email attachments (MIME) - SMTP only supports 7-bit ASCII. Base64 converts binary attachments into transmittable text.
- JSON Web Tokens (JWT) - The header and payload of every JWT are Base64-URL-encoded JSON objects.
- API authentication - HTTP Basic Auth encodes
username:passwordin Base64 (this is encoding, not encryption!). - Image-to-Base64 conversion - Store a small image directly in a database or config file as Base64.
Try It Yourself
Use the free online Base64 encoder/decoder to encode text instantly. For image-to-Base64, try the Image to Base64 Converter. All processing happens in your browser - nothing is uploaded.
Advertisement