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)

  1. Enter your data โ€” Paste any text, API credentials, or Base64 string in the box above.
  2. 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
  3. 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)

โŒ Mistake #1: Forgetting that Base64 increases data size

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.

โŒ Mistake #2: Using standard Base64 in URLs without encoding

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.

โŒ Mistake #3: Adding extra whitespace to Base64 strings

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.

โŒ Mistake #4: Assuming Base64 is encryption (it's NOT!)

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.

โŒ Mistake #5: Not handling Unicode characters correctly

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

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

Is Base64 encoding secure?

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).

Why does Base64 make data bigger?

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.

Does this tool save my data?

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.

What's the difference between standard and URL-safe Base64?

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.

Can Base64 handle emojis and non-English text?

Yes! Our tool properly handles UTF-8 encoding before Base64 conversion. This means emojis (๐Ÿ˜Š), Hindi (เคจเคฎเคธเฅเคคเฅ‡), Tamil (เฎตเฎฃเฎ•เฏเฎ•เฎฎเฏ), and all languages work correctly.

What's the maximum size this tool can handle?

The tool can handle up to ~10MB of text efficiently. For larger files, consider splitting into chunks or using command-line tools.

Why do I see "=" at the end of Base64 strings?

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.

Is this tool free?

Yes, completely free. No sign-up, no credit card, no hidden fees. Forever.

Related Tools You May Find Useful