Base64 Encode & Decode Tool — Complete Guide for Developers

Understand Base64 encoding from the ground up, and convert text or files instantly with our free browser-based tool.

🔤 Base64 Encoder / Decoder

Convert text and files to and from Base64 instantly — no uploads, no server processing.

Open Base64 Tool →

What Is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that represents binary data using 64 printable ASCII characters. It converts every 3 bytes of binary data into 4 ASCII characters, making binary data safe to transmit through text-based systems like email, JSON, XML, and URLs.

The 64 characters used are: A-Z, a-z, 0-9, +, and /, with = used for padding. This character set is safe for virtually every text-based protocol.

For example, the text "Hello, World!" encodes to:

SGVsbG8sIFdvcmxkIQ==

And decoding SGVsbG8sIFdvcmxkIQ== gives you back "Hello, World!" exactly. The encoding is fully reversible — no data is lost.

Why Does Base64 Exist?

Base64 solves a fundamental problem in computing: many protocols and systems are designed to handle text, not arbitrary binary data. Email (SMTP), for instance, was originally designed for 7-bit ASCII text. If you tried to send a binary file directly through email, certain bytes would be interpreted as control characters and corrupt the data.

Base64 encoding transforms any binary data — images, PDFs, encrypted content, compressed files — into safe ASCII text that survives transmission through text-only systems.

Common Use Cases for Base64

1. Email Attachments (MIME)

Every email attachment you've ever sent was Base64-encoded. The MIME standard uses Base64 to embed binary files within the text-based email format. Your email client handles the encoding/decoding transparently.

2. Data URIs in HTML and CSS

You can embed images, fonts, and other assets directly in HTML or CSS using Base64 data URIs:

<img src="data:image/png;base64,iVBORw0KGgo..." />

This eliminates an HTTP request for the resource, which can improve performance for small assets. For a detailed guide on image encoding specifically, check out our complete Base64 image encoding tutorial.

3. API Authentication

HTTP Basic Authentication encodes the username:password pair in Base64. The Authorization header looks like:

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

Important: Base64 is encoding, not encryption. The credentials above decode to username:password. Always use HTTPS with Basic Auth.

4. JSON Payloads with Binary Data

JSON only supports text. When you need to include binary data (like a file upload) in a JSON API request, Base64 encoding is the standard approach:

{
  "filename": "document.pdf",
  "content": "JVBERi0xLjQKMSAw..."
}

5. JWTs (JSON Web Tokens)

JWTs use Base64URL encoding (a URL-safe variant) for their header and payload segments. Every JWT you've worked with contains Base64-encoded JSON. If you need to decode JWTs, try our JWT decoder tool and guide.

Base64 Variants You Should Know

The Size Overhead

Base64 encoding increases data size by approximately 33%. Every 3 bytes of input become 4 bytes of output. This is an inherent tradeoff — you gain compatibility at the cost of size.

For small assets (icons, thumbnails, small config blobs), the overhead is negligible. For large files, it becomes significant. A 1MB image becomes ~1.33MB when Base64-encoded. This is why you generally shouldn't Base64-encode large images for web embedding — use regular file URLs instead.

Base64 in Every Language

// JavaScript
btoa("Hello")           // "SGVsbG8="
atob("SGVsbG8=")        // "Hello"

# Python
import base64
base64.b64encode(b"Hello")  # b'SGVsbG8='
base64.b64decode(b"SGVsbG8=")  # b'Hello'

// Java
Base64.getEncoder().encodeToString("Hello".getBytes());
new String(Base64.getDecoder().decode("SGVsbG8="));

# CLI
echo -n "Hello" | base64        # SGVsbG8=
echo "SGVsbG8=" | base64 -d     # Hello

Common Mistakes with Base64

When NOT to Use Base64

For more practical examples and use cases, read our comprehensive guide on what Base64 encoding is used for in real-world development.

Encode or Decode Base64 Now

Paste text or drag-and-drop a file. Instant conversion, completely private.

Open Base64 Tool →

Recommended Tools & Resources

Level up your workflow with these developer tools:

Cloudinary Media API → Cloudflare Workers → Computer Networking: A Top-Down Approach →

Dev Tools Digest

Get weekly developer tools, tips, and tutorials. Join our developer newsletter.

Frequently Asked Questions

What is Base64 encoding?

Base64 is a binary-to-text encoding scheme that converts binary data into a string of ASCII characters using 64 printable characters (A-Z, a-z, 0-9, +, /). It's used to safely transmit binary data through text-based systems.

When should I use Base64 encoding?

Use Base64 for: embedding images in HTML/CSS (data URIs), encoding binary data in JSON/XML, email attachments (MIME), storing binary data in databases that only support text, and passing data through URL parameters.

Does Base64 encoding increase file size?

Yes, Base64 increases data size by approximately 33%. A 1MB file becomes ~1.37MB when Base64 encoded. This is the tradeoff for text-safe encoding. For large files, it's better to use direct binary transfer.