← Tools

Base64 Encoding and Decoding: Complete Guide with Examples

📅 June 12, 2026  |  🏷️ Base64  |  ⏱️ 5 min read

Base64 encoding is everywhere — from API authentication to embedding images in HTML to sending email attachments. But what exactly is it, and when should you use it? Here's the complete guide.

What Is Base64 Encoding?

Base64 is a binary-to-text encoding scheme. It converts binary data (bytes) into a string of 64 ASCII characters (A-Z, a-z, 0-9, +, /). This is necessary because many systems — email, HTTP headers, JSON — can only handle text. Base64 lets you safely transmit binary data (images, files, encrypted data) through text-only channels.

Base64 vs Encryption

⚠️ Base64 is NOT encryption! Base64 encoding provides zero security. Anyone can decode a Base64 string back to its original form. If you need security, use AES, RSA, or another encryption algorithm — not Base64. Base64 is for transport compatibility, not security.

Real-World Base64 Examples

1. HTTP Basic Authentication

When you access a password-protected API or website, the browser sends credentials as Base64:

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

The string dXNlcm5hbWU6cGFzc3dvcmQ= is Base64 for username:password. Try decoding it with our free Base64 decoder.

2. Data URIs (Embedded Images)

Instead of linking to an external image file, you can embed it directly in HTML or CSS:

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

This is useful for small icons and eliminates HTTP requests, but it increases HTML file size by ~33% (Base64 encoding overhead).

3. Email Attachments (MIME)

Email was designed for text. Attachments (images, PDFs) are converted to Base64 embedded in the email body. When you receive an email with an attachment, your mail client decodes the Base64 back into the original file.

4. JSON Web Tokens (JWT)

JWTs consist of three Base64-encoded parts separated by dots:

eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOjQyfQ.abc123signature

The first part is the header (algorithm), the second is the payload (data), and the third is the signature. Decode the first two parts with our tool to see what's inside.

5. Storing Binary in JSON

JSON doesn't support binary data. If you need to store an image thumbnail in a JSON field, encode it as Base64 first: {"photo": "/9j/4AAQSkZJRg..."}.

How to Encode and Decode Base64 Online

  1. Go to the DevTools Base64 encoder/decoder.
  2. To encode: Type or paste your text, click "Encode to Base64." The Base64 string appears instantly.
  3. To decode: Paste a Base64 string, click "Decode from Base64." The original text appears.

The Base64 Alphabet

Base64 uses 64 characters: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

The = character at the end of some Base64 strings is padding. It indicates how many padding bytes were added to reach a multiple of 4. You'll often see = or == at the end.

💡 Pro Tip: Base64 increases data size by about 33%. If you're encoding a 3MB image, the Base64 string will be about 4MB. For large files, consider alternatives: upload the file to a server and transmit a URL instead of Base64-encoding the entire file.
Encode or Decode Instantly — Free

Type or paste, encode or decode. Instant results, no signup.

Open Base64 Tool →
← Back to DevTools Blog