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.
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
| Format | MIME Type | Prefix string | |
|---|---|---|---|
| PNG Image | image/png | data:image/png;base64, | |
| JPEG Image | image/jpeg | data:image/jpeg;base64, | |
| GIF Image | image/gif | data:image/gif;base64, | |
| SVG Image | image/svg+xml | data:image/svg+xml;base64, | |
| WebP Image | image/webp | data:image/webp;base64, | |
| PDF Document | application/pdf | data:application/pdf;base64, | |
| Plain Text | text/plain | data:text/plain;base64, | |
| JSON | application/json | data:application/json;base64, | |
| HTML | text/html | data:text/html;base64, | |
| CSS | text/css | data: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 btoa(), atob(), TextEncoder, and FileReader.