Base64 encoding converts binary data into ASCII text. Learn how it works, when to use it, how to encode and decode Base64 online, and its role in web development and email.
What Is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts binary data (like images, files, or raw bytes) into a string of ASCII characters. The name "Base64" comes from the fact that it uses 64 characters — A-Z, a-z, 0-9, +, and / — plus = as a padding character.
The core purpose: allow binary data to be safely transmitted over systems that only handle text. HTTP headers, JSON payloads, HTML attributes, and email bodies all deal in text — Base64 lets you embed binary content in these contexts.
How Base64 Encoding Works
Base64 works by taking 3 bytes (24 bits) of binary data at a time and splitting them into four 6-bit groups. Each 6-bit group is then mapped to one of the 64 characters in the Base64 alphabet.
For example, encoding the text Man:
M a n
77 97 110 (ASCII decimal values)
01001101 01100001 01101110 (binary)
Split into 6-bit groups: 010011 010110 000101 101110
Mapped to Base64: T W F u
Result: TWFu
This process increases file size by roughly 33% (every 3 bytes become 4 characters), but makes the data safe to transmit as text.
When Is Base64 Used?
Embedding Images in HTML and CSS
You can embed images directly in HTML or CSS using a data URI — no separate image file needed:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." />
Or in CSS:
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...');
This eliminates an HTTP request for the image, which can be beneficial for small icons or favicons. Use our Image to Base64 converter to generate data URIs.
Email Attachments
Email protocols (SMTP, MIME) are text-based. When you send an email attachment, your email client Base64-encodes the file and includes it as text in the email body. The recipient's client decodes it back into the original file.
API Authentication
HTTP Basic Authentication encodes credentials as Base64: username:password becomes a Base64 string sent in the Authorization header. Note that Base64 is encoding, not encryption — it provides no security on its own. Always use HTTPS.
JSON Web Tokens (JWT)
JWTs use Base64URL encoding (a variant that uses - and _ instead of + and / to be URL-safe) to encode the header, payload, and signature sections of the token.
Storing Binary Data in Databases
When you need to store binary data (like images or files) in a text-based database field, Base64 encoding is a common approach.
Base64 vs. Encryption
This is a critical misconception to clear up: Base64 is not encryption. It provides no security. Any Base64 string can be decoded instantly by anyone who sees it. It's purely a format conversion — making binary data representable as text.
Don't use Base64 to "hide" sensitive data. Use proper encryption (AES, RSA) for that.
How to Encode and Decode Base64 Online
Need to quickly convert text or data to/from Base64? NeatTools provides free, instant tools:
- Base64 Encoder — convert text or data to Base64
- Base64 Decoder — decode a Base64 string back to its original form
- Image to Base64 — generate data URI from an image file
- Base64 to Image — convert a Base64 string back into a viewable image
Practical Example: Embedding a Small Icon
Suppose you have a small checkmark icon (500 bytes as a PNG). Converting it to Base64 gives you ~670 characters. You can embed it directly in your stylesheet:
.icon-check {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...');
width: 16px;
height: 16px;
}
This eliminates the HTTP request for the icon file — a small but real performance benefit for frequently-used small images.
Conclusion
Base64 is a fundamental encoding scheme that's woven through web development, email, APIs, and security tokens. Understanding how it works — and how to quickly encode or decode values — is a practical skill for any developer. Use our free Base64 tools for instant conversions in your browser.