Base64 Encoding Explained: What It Is and When to Use It
Understand Base64 encoding, how it works, where it is used (JWT, data URLs, API images), and how to encode and decode online.
What Is Base64?
Base64 is an encoding scheme that converts binary data into a string of 64 printable ASCII characters. It is not encryption — it is not secret. Anyone with the Base64 string can instantly decode it.
The 64 characters used: A-Z (26), a-z (26), 0-9 (10), + and / (2), with = for padding.
Why Base64 Exists
Many internet protocols were designed for 7-bit ASCII text only. Binary data (images, files, executables) would corrupt when passed through text-only channels. Base64 converts binary to safe ASCII that any text system can transmit without corruption.
Size Trade-off
Base64 increases data size by exactly 33%. Three bytes of binary become four Base64 characters. A 100KB image becomes approximately 133KB in Base64.
Where Base64 Is Used
CSS data URLs: background-image: url('data:image/png;base64,...') embeds images directly in CSS, eliminating an HTTP request. Good for small images under 10KB.
JWT tokens: JSON Web Tokens use Base64URL (a URL-safe variant) for the header and payload sections.
HTTP Basic Authentication: The Authorization header contains Base64 of username:password. Not secure without HTTPS.
API image responses: Some APIs return images as Base64 strings in JSON responses.
Email attachments: MIME protocol uses Base64 to send binary attachments through text-based email.
Encoding vs Encryption
Base64 is encoding — not security. Anyone can decode it instantly. Never use Base64 to protect sensitive information. Use AES-256 or similar encryption for actual security.
Frequently asked questions
Is Base64 the same as encryption?
No — Base64 is encoding, not encryption. Anyone can decode it instantly. It exists for compatibility (transmitting binary through text channels), not security.
Why does Base64 make files bigger?
Base64 represents every 3 bytes of binary as 4 characters, creating a 33% size overhead. This is the trade-off for making binary data ASCII-safe.
What is the difference between Base64 and Base64URL?
Base64URL replaces + with - and / with _ to make the encoded string safe for use in URLs and filenames. Used in JWT tokens and OAuth.
Put this guide into practice with our free online tool — no signup required.
Open tool