What is Base64 Encoding?
Base64 is a binary-to-text encoding scheme. It converts binary data (images, files, bytes) into a string of ASCII characters (letters, numbers, +, /, =). The name "Base64" comes from the 64-character alphabet it uses.
The encoded output is always ~33% larger than the original binary data, but the data becomes safe to transmit in text-based systems like email, JSON, or URLs.
Why and When is Base64 Used?
1. Embedding Images in CSS/HTML
You can embed small images directly in your code as Base64 strings, eliminating an HTTP request:
background-image: url('data:image/png;base64,iVBORw0KGgo...');
Great for tiny icons. Not recommended for large images (performance issue).
2. Email Attachments
Email protocols (SMTP) only support ASCII text. Binary files (images, PDFs) are Base64-encoded before being attached to emails.
3. JWT Tokens (JSON Web Tokens)
JWTs use Base64URL encoding (a variant of Base64 safe for URLs) to encode the header and payload. When you see a token like eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoicmFodWwifQ.xxxx, those parts are Base64URL encoded JSON.
4. API Data Transmission
When sending binary data (like an uploaded image) via a JSON API, the image is typically Base64-encoded and included as a string in the JSON body.
5. Basic Authentication Headers
HTTP Basic Auth encodes username:password in Base64:
Authorization: Basic cmFodWw6cGFzc3dvcmQxMjM=
How Base64 Works (Simplified)
Base64 takes 3 bytes (24 bits) of binary data and splits them into 4 groups of 6 bits each. Each 6-bit group maps to one of 64 characters in the Base64 alphabet. If the input isn't divisible by 3, = padding is added.
Base64 vs Encryption: Don't Confuse Them
Base64 is NOT encryption. It's encoding — anyone can decode it in seconds. Never use Base64 to "secure" passwords or sensitive data. Use it only for data transport, not security.
Use the Free ToolDost Base64 Encoder/Decoder
The ToolDost Base64 Encoder/Decoder lets you:
- Encode any text to Base64 instantly
- Decode Base64 strings back to text
- One-click copy to clipboard
- Works with Unicode/multilingual text
More Developer Tools
Topics Covered