Base64 Encoding Explained - What It Is and How to Use It
Base64 Encoding Explained - What It Is and How to Use It
Understanding Base64 encoding: what it is, how it works, and when to use it. Includes practical examples and our free online encoder/decoder tool.
March 14, 20262 min read
What is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It converts binary data into a set of 64 characters (A-Z, a-z, 0-9, +, /) that can be safely transmitted over text-based protocols.
Why Use Base64?
- Email attachments: MIME uses Base64 to encode binary files in emails
- Data URIs: Embed images directly in HTML/CSS
- API authentication: HTTP Basic Auth encodes credentials in Base64
- JWT tokens: JSON Web Tokens use Base64URL encoding
- Configuration files: Safely store binary data in text files
How Base64 Works
- Take the binary data (e.g., text converted to ASCII bytes)
- Split into groups of 6 bits (instead of the usual 8)
- Map each 6-bit group to one of 64 characters
- Add padding (
=) if the data doesn't divide evenly
Example
Text: Hi β ASCII: 72 105 β Binary: 01001000 01101001
Split into 6-bit groups: 010010 000110 1001xx
Map to Base64: S G k + padding = β Result: SGk=
Common Use Cases
Encoding an Image for HTML
<img src="data:image/png;base64,iVBORw0KGgo..." />
HTTP Basic Authentication
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Storing Binary Data in JSON
{
"file": "SGVsbG8gV29ybGQ=",
"filename": "hello.txt"
}
Base64 vs Encryption
Important: Base64 is not encryption. It's encoding β anyone can decode it. Never use Base64 alone to protect sensitive data.
Try It Now
Use our free Base64 encoder/decoder to encode or decode Base64 strings instantly!