Base64 Encoder & Decoder

Encode and decode text or files to Base64 instantly. Live mode, smart detection, history, and a full reference cheat sheet. Everything runs in your browser — your data never leaves your device.

Ctrl+Enter encode · Alt+Enter decode · Ctrl+E encode · Ctrl+Shift+C copy
Input
Characters
0
Bytes (UTF-8)
0
Output
Characters
0
Bytes
0
Ratio
📄
Drop a file here
or click to browse — any file type

Base64 Alphabet — All 64 Characters

Hover any character to see its decimal value and 6-bit binary. The = sign is padding only — it carries no data.

Common Data URI Prefixes

FormatMIME TypePrefix string
PNG Imageimage/pngdata:image/png;base64,
JPEG Imageimage/jpegdata:image/jpeg;base64,
GIF Imageimage/gifdata:image/gif;base64,
SVG Imageimage/svg+xmldata:image/svg+xml;base64,
WebP Imageimage/webpdata:image/webp;base64,
PDF Documentapplication/pdfdata:application/pdf;base64,
Plain Texttext/plaindata:text/plain;base64,
JSONapplication/jsondata:application/json;base64,
HTMLtext/htmldata:text/html;base64,
CSStext/cssdata:text/css;base64,

Code Snippets

JavaScript — Encode & Decode

Encode a string (Unicode-safe using TextEncoder):

// Encode string to Base64 (handles Unicode)
function encodeBase64(str) {
  const bytes = new TextEncoder().encode(str);
  const binary = String.fromCharCode(...bytes);
  return btoa(binary);
}

// Decode Base64 back to string
function decodeBase64(b64) {
  const binary = atob(b64);
  const bytes = Uint8Array.from(binary, c => c.charCodeAt(0));
  return new TextDecoder().decode(bytes);
}

Use in a fetch request (Basic Auth header):

const credentials = btoa('username:password');
fetch('/api/data', {
  headers: { 'Authorization': 'Basic ' + credentials }
});
Python — Encode & Decode

Standard library — no dependencies needed:

import base64

# Encode string to Base64
encoded = base64.b64encode(b'Hello, World!').decode('utf-8')
print(encoded)  # SGVsbG8sIFdvcmxkIQ==

# Decode Base64 back to bytes
decoded = base64.b64decode(encoded)
print(decoded.decode('utf-8'))  # Hello, World!

# URL-safe variant
url_safe = base64.urlsafe_b64encode(b'data+here/now')
decoded2 = base64.urlsafe_b64decode(url_safe)

Encode a file to Base64:

import base64

with open('image.png', 'rb') as f:
    b64_str = base64.b64encode(f.read()).decode('utf-8')

data_uri = f'data:image/png;base64,{b64_str}'
HTML — Embed Files with Data URIs

Embed an image without an external HTTP request:

<!-- Inline PNG image -->
<img src="data:image/png;base64,iVBORw0KGgo..." alt="Logo">

<!-- Inline SVG as background -->
<style>
  .icon {
    background-image: url("data:image/svg+xml;base64,PHN2Zy4uLg==");
    width: 24px; height: 24px;
  }
</style>

<!-- Inline font face -->
<style>
  @font-face {
    font-family: 'MyFont';
    src: url('data:font/woff2;base64,d09GMgAB...') format('woff2');
  }
</style>
HTTP & APIs — Auth Headers & Payloads

HTTP Basic Authentication (RFC 7617):

# HTTP header — base64(username:password)
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

# curl example
curl -H "Authorization: Basic $(echo -n 'user:pass' | base64)" \
     https://api.example.com/data

Sending binary data in a JSON API payload:

// JSON payload with Base64-encoded file
{
  "filename": "photo.jpg",
  "mime_type": "image/jpeg",
  "data": "/9j/4AAQSkZJRgAB..."
}

// JWT token structure (URL-safe Base64, no padding)
// header.payload.signature
// eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIn0.abc123
100% Private. Your data never leaves your device. All encoding and decoding happens locally in your browser using the Web APIs: btoa(), atob(), TextEncoder, and FileReader.

How to Use

1

Choose Your Mode

Select Text Mode to encode/decode strings, File Mode to convert binary files, or Reference for the alphabet table and code examples.

2

Enter or Drop Your Data

Type or paste text — the tool auto-detects whether it looks like Base64 or plain text. Enable Live Mode to encode as you type. Drag & drop files in File Mode.

3

Copy, Download, or Restore

Copy the result to clipboard, download it as a .txt file, or swap input/output. Recent operations are saved in History for quick restoration.

Overhead: ⌈n÷3⌉ × 4 bytes URL-safe: + → − and / → _ Padding: = aligns to 4-char blocks Alphabet: 64 chars · 6 bits each

Frequently Asked Questions

What is Base64 encoding?

Base64 is a binary-to-text encoding scheme that represents binary data using 64 printable ASCII characters (A–Z, a–z, 0–9, +, /). It's used to embed images in HTML/CSS, transmit binary data over text-based protocols like email (MIME), store complex data in JSON or XML, and pass binary payloads through REST APIs.

What is URL-safe Base64?

Standard Base64 uses + and /, which have special meaning in URLs. URL-safe Base64 (RFC 4648 §5) replaces + with - and / with _, and omits padding = signs. This lets the encoded string appear safely in URLs and filenames without percent-encoding.

Why is the Base64 output larger than the input?

Base64 encodes 3 bytes into 4 characters, producing approximately 33% overhead. The formula is ⌈n/3⌉ × 4 output characters for n input bytes. This overhead is the trade-off for representing arbitrary binary data as printable ASCII text.

Is my data safe using this tool?

Yes. This tool runs entirely in your browser using JavaScript. No data is sent to any server. You can verify this by disconnecting from the internet — the tool will continue to work perfectly because everything is processed locally using btoa(), atob(), TextEncoder, and the FileReader API.

Can I encode binary files like images or PDFs?

Yes. Switch to File Mode and drop any file onto the drop zone. The tool reads the file using the FileReader API and encodes the raw bytes to Base64. You can optionally include the data URI prefix (e.g., data:image/png;base64,...) for direct use in HTML or CSS.

Is Base64 the same as encryption?

No. Base64 is encoding, not encryption. Anyone with the Base64 string can instantly decode it — there is no secret key involved. Never use Base64 to protect sensitive data. Use proper encryption (AES, ChaCha20) for confidentiality and proper hashing (bcrypt, Argon2) for passwords.

What is the maximum file size I can encode?

There is no hard limit — it depends on your browser's available memory. In practice, files up to ~50 MB work fine in modern browsers. Very large files (>100 MB) may cause the tab to slow down or run out of memory. The tool shows a warning for files over 5 MB.

How do I decode Base64 in Python?

Use the built-in base64 module: import base64; decoded = base64.b64decode("SGVsbG8="). For URL-safe Base64, use base64.urlsafe_b64decode() instead. The result is a bytes object — call .decode('utf-8') to get a string.

How do I decode Base64 in JavaScript?

For ASCII text: atob("SGVsbG8=") returns the decoded string. For Unicode strings, use TextDecoder: new TextDecoder().decode(Uint8Array.from(atob(b64), c => c.charCodeAt(0))). For URL-safe Base64, replace - with + and _ with / before calling atob().

What is a data URI?

A data URI is a scheme that embeds file data directly in a URL: data:[mime-type];base64,[encoded-data]. For example, data:image/png;base64,iVBORw0... is a complete PNG image encoded inline. Browsers render data URIs directly without making an HTTP request, making them useful for embedding small assets.

What is the difference between Base64 and hex encoding?

Both represent binary data as text. Hex uses 16 characters (0–9, a–f), so each byte becomes 2 hex digits — 100% overhead. Base64 uses 64 characters (6 bits per character), so 3 bytes become 4 characters — ~33% overhead. Base64 is more space-efficient; hex is easier to read and debug.

Can I use Base64 for passwords?

No. Base64 encoding provides no security — it is trivially reversible by anyone. For storing passwords, use a proper password hashing algorithm like bcrypt, Argon2, or PBKDF2. These are one-way functions designed to be computationally expensive, making brute-force attacks impractical.

Common Use Cases

📷
Embed Images in HTML

Inline images directly in HTML without extra HTTP requests. Ideal for small icons and logos.

<img src="data:image/png;base64,...">
🎨
CSS Background Images

Embed SVG icons or small images in CSS stylesheets to eliminate additional file requests.

background: url("data:image/svg+xml;base64,...")
🔒
HTTP Basic Auth

RFC 7617 uses Base64 to transmit credentials in the Authorization header.

Authorization: Basic base64(user:pass)
🔑
JWT Tokens

JSON Web Tokens use URL-safe Base64 (no padding) for header, payload, and signature segments.

eyJhbGciOiJIUzI1NiJ9.eyJzdWIi...
📧
Email Attachments

MIME email format (RFC 2045) encodes binary attachments as Base64 for safe transmission over text-only protocols.

Content-Transfer-Encoding: base64
📋
API Binary Payloads

REST APIs that use JSON cannot send raw binary. Base64 encodes images or files into JSON-safe strings.

{"file": "/9j/4AAQSkZJRgAB..."}