Skip to main content

Base64 use cases

Base64 encoding is embedded in everyday web development, security, and networking. Here are the most common scenarios where you will encounter it — each with a concrete code example and a direct link to try it in the tool.

Use caseVariantKey detail
JWT header / payloadURL-safe (Base64URL)Three dot-separated segments; header + payload are readable
Data URIsStandarddata:<mime>;base64,<data> in HTML or CSS
Email attachmentsStandardContent-Transfer-Encoding: base64 in MIME
HTTP Basic AuthStandardAuthorization: Basic base64(user:pass) — not encrypted
PEM keys & certificatesStandardBase64-encoded DER wrapped in -----BEGIN … -----
JSON API binary fieldsStandardEncodes bytes as a string value in JSON
CSS / HTML asset inlineStandardEliminates HTTP requests for small files (< ~8 KB)
WebSocket binaryStandardBinary frames encoded as text for proxy compatibility

JSON Web Tokens (JWT)

URL-safe

A JWT is three Base64URL-encoded JSON objects separated by dots: a header, a payload (claims), and a signature. The header and payload are human-readable once decoded — no key needed. This makes Base64 decoding a routine debugging task for auth flows.

Structure of a JWT
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9   ← header
.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkFsaWNlIiwiaWF0IjoxNTE2MjM5MDIyfQ   ← payload
.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c   ← signature
Decode the payload (paste into the tool)
eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkFsaWNlIiwiaWF0IjoxNTE2MjM5MDIyfQ
Decoded result
{"sub":"1234567890","name":"Alice","iat":1516239022}
Decode a JWT payload in the tool

Data URIs — inline images & fonts

Standard

The data URI scheme embeds binary assets directly in HTML, CSS, or SVG, eliminating an HTTP request. Small images, SVG icons, and critical fonts are the most common targets. The browser decodes the Base64 synchronously during parsing, so the asset is immediately available with no additional HTTP request.

Data URI format
data:<mediatype>;base64,<base64-encoded-data>
CSS — inline a background image
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0i...");
HTML — inline a PNG favicon
<link rel="icon" href="data:image/png;base64,iVBORw0KGgo..." />
Upload an image to encode it

Email attachments (MIME)

Standard

SMTP was designed to carry 7-bit ASCII text. Sending any binary file — a PDF, an image, a spreadsheet — requires encoding it as Base64 inside a MIME multipart message. Every email client and server in use today handles this encoding and decoding transparently.

MIME part for a PDF attachment
Content-Type: application/pdf; name="report.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="report.pdf"

JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwKL0xlbmd0aCAzIDAgUgo+...
Encode a PDF with the file upload

Binary data in JSON APIs

Standard

JSON has no native binary type. When a REST or GraphQL API needs to transmit binary content — a generated image, a signed token, an encrypted blob, or a file chunk — it Base64-encodes the bytes and stores them as a JSON string. This is also how the Web Crypto API returns raw key material.

API response with a Base64-encoded image
{
  "id": "img_42",
  "format": "image/webp",
  "data": "UklGRlYAAABXRUJQVlA4IEoAAADQAQCdASo..."
}
Web Crypto API — export a raw key
const key = await crypto.subtle.generateKey(
  { name: "AES-GCM", length: 256 }, true, ["encrypt", "decrypt"]
);
const raw = await crypto.subtle.exportKey("raw", key);
const b64 = btoa(String.fromCharCode(...new Uint8Array(raw)));
Decode a Base64 API value

PEM certificates & cryptographic keys

Standard

PEM (Privacy-Enhanced Mail) format stores cryptographic objects — TLS certificates, RSA keys, ECDSA keys, SSH public keys, GPG keys — as Base64-encoded DER data wrapped in ASCII header and footer lines. Any time you copy an SSH key or paste a certificate into a config file, you are handling Base64.

PEM format (RSA public key)
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2a2rwplBQLzHPZe5TNJT
...
-----END PUBLIC KEY-----
The body between the headers is standard Base64
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2a2rwplBQLzHPZe5TNJT
Decode a PEM body in the tool

HTTP Basic Authentication

Standard

HTTP Basic Auth encodes the username and password as Base64 and sends them in the Authorization header on every request. This is not encryption — the credentials can be decoded instantly. Always use Basic Auth over HTTPS, never plain HTTP.

Encoding credentials
username:password  →  dXNlcm5hbWU6cGFzc3dvcmQ=
HTTP Authorization header
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Encode "username:password" in the tool

Fonts & SVGs in CSS

Standard

Build tools like Vite and webpack automatically inline small assets (typically under 4–8 KB) as Base64 data URIs to eliminate HTTP round-trips. Custom icon fonts, small SVG sprites, and critical background images are common targets. For offline-first PWAs this technique ensures assets are available even without a network connection.

Inline a WOFF2 font in CSS
@font-face {
  font-family: "MyFont";
  src: url("data:font/woff2;base64,d09GRg...") format("woff2");
}
Vite / webpack config (auto-inline under 4 KB)
// vite.config.ts
export default {
  build: {
    assetsInlineLimit: 4096,  // bytes; files smaller than this are inlined
  },
};
Upload a font file to encode it

WebSocket and binary protocols

Standard

WebSocket supports both text and binary frames. Some libraries or intermediaries (logging proxies, older firewalls) only pass text frames reliably. In these environments, binary protocol messages are Base64-encoded before sending and decoded on receipt — a common pattern in browser-based SSH terminals, RDP clients, and IoT dashboards.

Sending binary data over a text WebSocket
// Sender
const bytes = new Uint8Array([0x01, 0x02, 0x03]);
const b64 = btoa(String.fromCharCode(...bytes));
socket.send(JSON.stringify({ type: "bin", data: b64 }));

// Receiver
const msg = JSON.parse(event.data);
const decoded = Uint8Array.from(atob(msg.data), c => c.charCodeAt(0));
Encode binary values in the tool

All operations run locally in your browser. No data is ever uploaded.

Open base64tool →