Base64 Encoder/Decoder
Encode text to Base64 or decode Base64 to text. Perfect for web development, API integration, data embedding, and encoding binary data for text-based protocols.
About Base64 Encoding
What is Base64?
Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It uses a set of 64 characters (A-Z, a-z, 0-9, +, /) to encode data, making it safe for transmission over text-based protocols that don't support binary data.
Common Use Cases
- Web Development: Embedding images and fonts directly in CSS and HTML
- API Authentication: Encoding credentials for HTTP Basic Authentication
- Email Attachments: MIME encoding for binary attachments
- Data URIs: Embedding small files directly in web pages
- JSON Data: Including binary data in JSON payloads
- Configuration Files: Storing binary data in text-based config files
Examples and Applications
Data URI Example
Original: Small PNG image
Base64: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==
HTTP Basic Auth Example
Original: username:password
Base64: dXNlcm5hbWU6cGFzc3dvcmQ=
Header: Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Technical Details
How Base64 Works
- Character Set: 64 characters (A-Z, a-z, 0-9, +, /)
- Padding: Uses "=" character for padding when needed
- Size Increase: Encoded data is ~33% larger than original
- Safety: Only uses characters safe for URLs and filenames
Encoding Process
- Convert input to binary (8-bit bytes)
- Group binary data into 6-bit chunks
- Map each 6-bit value to Base64 character
- Add padding if necessary
Best Practices
- Use for Small Data: Base64 increases size by ~33%, so use for small files only
- URL-Safe Variant: Use Base64URL for URLs (replaces + with -, / with _)
- No Line Breaks: Remove line breaks when using in APIs or JSON
- Validate Input: Always validate Base64 input before decoding
- Security Note: Base64 is encoding, not encryption - data is not secure
- MIME Headers: Include proper MIME type when embedding in data URIs
Frequently Asked Questions
Is Base64 encryption?
No, Base64 is encoding, not encryption. It's easily reversible and provides no security. It's designed for data compatibility, not confidentiality.
Why does Base64 make data larger?
Base64 uses 6 bits per character but stores them in 8-bit bytes, creating ~33% overhead. This trade-off ensures compatibility with text-based systems.
When should I use Base64?
Use Base64 when you need to embed binary data in text formats (JSON, XML, HTML), transmit binary data over text protocols, or store binary data in text-based systems.
What's the difference between Base64 and Base64URL?
Base64URL is URL-safe: it replaces + with -, / with _, and removes padding. This prevents issues when Base64 data is used in URLs or filenames.