Base64 Encoder / Decoder
Encode or decode strings online with UTF-8 and URL-safe options. Perfect for developers.
Text to Encode
Base64 Output
Complete Guide to Base64 Encoding and Decoding
What is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It's widely used in web development, email systems, and data transmission protocols. The name "Base64" comes from the fact that it uses 64 different characters to represent data: A-Z (26 characters), a-z (26 characters), 0-9 (10 characters), plus two additional characters that vary by implementation.
Base64 encoding is essential for transmitting binary data over text-based protocols like HTTP, SMTP, and JSON. It ensures that data remains intact during transmission without modification. This makes it particularly useful for embedding images in HTML/CSS, storing binary data in databases, and transmitting files through APIs.
How Base64 Encoding Works
The Base64 encoding process works by taking groups of three 8-bit bytes (24 bits total) and converting them into four 6-bit values. These 6-bit values are then mapped to characters in the Base64 alphabet. If the input doesn't divide evenly by 3, padding characters (=) are added to make the output length a multiple of 4.
Example:
Original: "Hello"
Binary: 01001000 01100101 01101100 01101100 01101111
Base64: "SGVsbG8="
Common Use Cases for Base64
Web Development
- • Embedding images in HTML/CSS (data URIs)
- • Storing binary data in JSON APIs
- • Authentication tokens (JWT)
- • File uploads and downloads
Email Systems
- • MIME email attachments
- • Email headers and content
- • SMTP protocol data
- • Email signatures
URL-Safe Base64 vs Standard Base64
Standard Base64 uses characters that can cause issues in URLs: + (plus) and / (slash) are reserved characters in URLs. URL-safe Base64 replaces these with - (minus) and _ (underscore) respectively, and removes padding characters (=) to create URL-safe strings.
Comparison:
Standard: "SGVsbG8+World/="
URL-Safe: "SGVsbG8-World_"
Best Practices for Base64 Usage
✅ Do's
- • Use for small binary data (images, files under 1MB)
- • Always validate input before encoding/decoding
- • Use URL-safe Base64 for URL parameters
- • Consider compression for large data
❌ Don'ts
- • Don't use for large files (increases size by ~33%)
- • Don't use for sensitive data without encryption
- • Don't rely on Base64 for security
- • Don't use for text that's already ASCII
Base64 in Different Programming Languages
JavaScript/Node.js
// Encode
btoa('Hello World')
// Decode
atob('SGVsbG8gV29ybGQ=')
Python
import base64
# Encode
base64.b64encode(b'Hello')
# Decode
base64.b64decode('SGVsbG8=')
Need more developer tools?
Check out our other free tools for developers and students.