Base64 Encoder & Decoder
Encode text to Base64 or decode Base64 back to text instantly. Essential for API keys, email attachments, and data transmission.
What is Base64 and Why Do You Need It?
Let me tell you about a startup founder who nearly lost a major client because of a simple encoding problem. He was building an integration with a banking API that required authentication tokens in Base64 format. He didn't know how to convert his API credentials, spent two days debugging, and almost missed the deadline.
Base64 would have solved his problem in 5 seconds.
๐ก What is Base64 Encoding?
Base64 is a method for converting binary data (or text) into a safe, text-only format that can be transmitted over channels designed for text. Think of it as a universal translator for data.
Real-world scenarios where Base64 is essential:
- ๐ง Email attachments โ Every image in your email is Base64 encoded
- ๐ API authentication โ Basic Auth headers use Base64 (username:password)
- ๐ผ๏ธ Embedded images โ Data URIs in HTML/CSS (like inline profile pictures)
- ๐ฆ JSON payloads โ Sending binary data in text-based APIs
- ๐ JWT tokens โ JSON Web Tokens use Base64url encoding
- ๐พ Local storage โ Storing binary data in browser localStorage
Why "Base64"? It uses 64 different characters (A-Z, a-z, 0-9, +, /) to represent binary data. This makes it safe to transmit over systems that might corrupt raw binary data.
How to Use the Base64 Encoder/Decoder (Step by Step)
- Enter your data โ Paste any text, API credentials, or Base64 string in the box above.
- Choose your operation:
- Encode to Base64 โ Converts regular text to Base64 format
- Decode from Base64 โ Converts Base64 back to original text
- Encode for URL Safe โ Converts + and / to - and _ (safe for URLs)
- Decode URL Safe โ Converts URL-safe Base64 back to standard
- Copy and use โ Click the copy button and paste into your code, API request, or configuration file.
7 Practical Examples (Real-World Scenarios)
๐ Example 1: API Authentication (Basic Auth)
The problem: You need to call an API that requires Basic Authentication with username "admin" and password "secret123".
Step 1 - Combine: admin:secret123
Step 2 - Encode to Base64: YWRtaW46c2VjcmV0MTIz
Step 3 - Add to HTTP header: Authorization: Basic YWRtaW46c2VjcmV0MTIz
๐ก Pro tip: Most API documentation includes this step, but now you can generate it instantly.
๐ผ๏ธ Example 2: Embedding an Image in HTML (Data URI)
The problem: You want to display a small logo without hosting it as a separate file.
Original image data (simplified): logo.png binary data...
After Base64 encoding: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA...
Usage in HTML: <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA...">
โ Benefit: No extra HTTP request = faster page load for small images.
๐ง Example 3: Email Attachment Encoding
The problem: SMTP (email protocol) was designed for text, not binary files.
Solution: Email clients automatically Base64 encode attachments.
Example: A PDF file named "invoice.pdf" is converted to a long Base64 string before being sent. Your email client decodes it automatically when you receive it.
๐ก You don't see this: It happens behind the scenes, but now you understand why!
๐ Example 4: JWT Token Verification
The problem: You received a JWT (JSON Web Token) and need to decode the payload.
JWT structure: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEyMywicm9sZSI6ImFkbWluIn0.signature
Middle part (payload) after decoding: {"userId":123,"role":"admin"}
๐ก How to check: Decode the middle section to see what data the token contains.
๐ Example 5: URL-Safe Encoding for API Parameters
The problem: Standard Base64 uses + and / which have special meanings in URLs.
Original text: Hello+World/Secret
Standard Base64: SGVsbG8rV29ybGQvU2VjcmV0 (contains + and /)
URL-Safe Base64: SGVsbG8rV29ybGQvU2VjcmV0 replaces + with - and / with _
Usage in URL: https://api.example.com/data?token=SGVsbG8rV29ybGQvU2VjcmV0 โ
Safe!
๐พ Example 6: Storing Binary Data in localStorage
The problem: Browser localStorage only stores strings, not binary data.
Solution: Convert binary data to Base64 string first.
Example (simplified):
// User's profile picture as binary data
const imageData = getImageBinary();
// Encode to Base64 for storage
const base64Image = btoa(imageData);
localStorage.setItem('profileImage', base64Image);
// Later, retrieve and decode
const storedImage = localStorage.getItem('profileImage');
const originalImage = atob(storedImage);
๐ฆ Example 7: Sending Binary Data in JSON API
The problem: JSON is text-only, but you need to send a file via API.
Solution: Convert file to Base64 before including in JSON.
JSON payload:
{
"filename": "report.pdf",
"content": "JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCg==",
"contentType": "application/pdf"
}
5 Common Base64 Mistakes (And How to Avoid Them)
The problem: Base64 encoding makes data about 33% larger than the original.
Example: A 1MB file becomes ~1.33MB after Base64 encoding.
Fix: Only use Base64 when necessary (email, JSON APIs, text-only channels). For large files, consider direct binary transfer.
The problem: Standard Base64 contains + and / characters that break URLs.
Wrong: https://api.com?token=abc+def/ghi (+ and / have special meanings)
Fix: Use URL-safe Base64 (replaces + with -, / with _) or URL-encode the Base64 string.
The problem: Some systems add line breaks every 64 characters (MIME format).
Wrong: Base64 with line breaks may cause decoding errors.
Fix: Remove all whitespace before decoding, or use our tool which handles it automatically.
The problem: Many beginners think Base64 is a form of encryption. It is NOT!
Truth: Base64 is encoding, not encryption. Anyone can decode it instantly. Never use Base64 to protect sensitive data.
Fix: For security, use real encryption (AES, RSA) or hashing (SHA-256). Base64 is only for data transport, not security.
The problem: JavaScript's btoa() function only works with ASCII characters (0-255).
Wrong: btoa("เคจเคฎเคธเฅเคคเฅ") โ Error! (Unicode character)
Fix: Our tool handles Unicode properly by first converting to UTF-8. Always use proper UTF-8 handling for international text.
5 Best Practices for Working with Base64
1. Use for small data only
Base64 adds 33% overhead. For images >100KB, host as separate files instead of embedding.
2. Always validate before decoding
Invalid Base64 strings cause errors. Our decoder validates first.
3. Use URL-safe for web APIs
When passing Base64 in URLs, always use the URL-safe variant.
4. Never store passwords in Base64
Base64 is reversible. Use proper password hashing (bcrypt, Argon2).
5. Handle Unicode properly
Always use UTF-8 encoding for non-English text before Base64 conversion.
Base64 vs Other Encoding Methods
Base64
Use for: Email attachments, API auth, data URIs, JWT tokens
Size increase: ~33%
Character set: A-Z, a-z, 0-9, +, /, =
Base64url
Use for: URLs, JWT tokens, web APIs
Size increase: ~33%
Character set: A-Z, a-z, 0-9, -, _
Hex (Base16)
Use for: Cryptography, color codes, debugging
Size increase: 100%
Character set: 0-9, A-F
Base32
Use for: Case-insensitive systems, manual entry
Size increase: ~60%
Character set: A-Z, 2-7
When NOT to Use Base64
- ๐ Password storage โ Base64 is reversible. Use bcrypt, Argon2, or PBKDF2 instead.
- ๐ผ๏ธ Large images (>100KB) โ Host as separate files. Base64 bloats size and slows page load.
- ๐ Files over 5MB โ The 33% size increase becomes significant. Use direct binary transfer.
- ๐ Search engine indexing โ Base64-encoded text won't be indexed by Google.
- ๐ Compressed data โ Base64 + compression is inefficient. Send compressed binary directly.
Industry-Specific Base64 Use Cases
๐ Web Development
Basic Auth headers, JWT tokens, data URIs, localStorage binary storage
๐ง Email Systems
MIME attachments, embedded images, email signatures
๐ Security
API keys, OAuth tokens, certificate encoding (PEM format)
๐ฑ Mobile Apps
Offline data storage, API communication, push notification payloads
๐๏ธ Database
Storing binary BLOBs in text columns, MongoDB Binary data type
โ๏ธ DevOps
Kubernetes secrets (Base64 encoded), Docker configs, CI/CD variables
Frequently Asked Questions
No, absolutely not. Base64 is encoding, not encryption. Anyone can decode it instantly. Never use Base64 to protect passwords, credit cards, or personal data. For security, use proper encryption (AES) or hashing (SHA-256, bcrypt).
Base64 uses 6 bits per character (64 possibilities) instead of 8 bits per byte. To represent 8-bit binary data, it needs more characters โ roughly a 33% size increase.
No. Everything runs in your browser. Your text, API keys, or credentials never leave your device. We don't store, log, or save any of your inputs. This is especially important for sensitive authentication data.
Standard Base64 uses + and / which have special meanings in URLs. URL-safe Base64 replaces + with - and / with _, making it safe to include in web addresses.
Yes! Our tool properly handles UTF-8 encoding before Base64 conversion. This means emojis (๐), Hindi (เคจเคฎเคธเฅเคคเฅ), Tamil (เฎตเฎฃเฎเฏเฎเฎฎเฏ), and all languages work correctly.
The tool can handle up to ~10MB of text efficiently. For larger files, consider splitting into chunks or using command-line tools.
The equals sign (=) is padding. Base64 works in groups of 4 characters. If the input doesn't divide evenly, padding is added to complete the last group.
Yes, completely free. No sign-up, no credit card, no hidden fees. Forever.