Skip to content
All posts
7 min read(updated October 20, 2026)

Base64 in the wild: data URIs, MIME, Basic auth and embedded fonts

From inline images to Authorization headers — a tour of the places Base64 already appears in your stack, and how to work with each one safely.

  • web
  • guide

Base64 isn’t a topic you study — it’s a thing you keep bumping into. Ten places below, one sharp observation each, and by the last one you’ll see it in headers, fonts, email bodies and CI logs without trying.

1. JSON Web Tokens

Every login token is three base64url parts joined by dots. Take the canonical example from jwt.io: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 decodes directly to {"alg":"HS256","typ":"JWT"} — the ey prefix is the Base64 of {" and appears on virtually every token ever issued. The third part of the canonical token, SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c, contains an underscore: JWTs use the URL-safe alphabet (- and _ instead of + and /) with no = padding, which is exactly why strict standard-alphabet decoders reject them. The JWT inspector reads all of it automatically.

The career-saving reminder: the payload is not secret. Base64 in a JWT is packaging, not protection — why Base64 is not encryption is worth reading before anyone drops a password into a token payload.

2. Email attachments (MIME)

Email is a text-only protocol wearing a multimedia costume. MIME’s Content-Transfer-Encoding: base64 is the costume: attachments ride in the message body, wrapped at 76 characters per line with CRLF endings — the number is straight from RFC 2045 §6.8, not a style choice. Open any saved .eml in a text editor and you’ll see it: a several-thousand-line block of uniform 76-char text that is your PDF.

Two practical notes: decoders must strip the line breaks (the decoder’s file tab does, and detects the result type automatically), and don’t confuse Base64 with quoted-printable, the other common transfer encoding in the same mailboxes. =3D sequences are hex, not Base64 — running them through a Base64 decoder returns nothing.

3. PEM certificates

Every TLS handshake you’ve ever looked at ended in PEM: -----BEGIN CERTIFICATE-----, 64 characters per line, -----END CERTIFICATE-----. That block is Base64 of the certificate’s DER form — the raw ASN.1 binary. The framing lines are text markers, not payload: each line carries exactly 64 chars, because PEM predates modern line-length indifference (RFC 7468 finally standardized it). The same wrapping covers private keys (BEGIN PRIVATE KEY), certificate signing requests, and public keys. Two details worth knowing: stripping the marker lines before decoding isn’t optional, and chain files (fullchain.pem from Let’s Encrypt, say) contain several PEM blocks back to back — a decoder that swallows them as one blob will parse exactly nothing.

4. Data URIs in CSS

@font-face {
  font-family: 'Inter';
  src: url(data:font/woff2;base64,d09GMg…) format('woff2');
}

Run grep -c 'data:' over any shipping CSS bundle and the longest match is almost always a font, not an image — subsetted fonts inline so neatly that even a three-glyph icon font can outsize the gradients around it. Bundlers codify the trade-off with a threshold — tools such as Vite inline files below a default limit (4 KB by assetsInlineLimit convention) and emit a separate file above it: smaller request counts, larger documents, zero caching, 33% size overhead — and fonts arrive straight in the render-blocking document rather than one parallel request later.

Got a data:image/png;base64,… you want to inspect? The base64-to-image tool turns the string back into a viewable, downloadable file — handy for verifying a mystery payload before you ship it.

5. Git, and GitHub’s API

git diff on a binary file shows the famously useless Binary files a/logo.png and b/logo.png differ. Git’s own binary patch format exists but uses base85, not Base64 — a common trap is feeding a GIT binary patch blob to a Base64 decoder. Where Base64 genuinely appears is above Git: the GitHub REST API. Fetch any repo file via GET /repos/{owner}/{repo}/contents/path and the content field is Base64-encoded bytes — this single fact is why every “download a single file without cloning” script you’ve seen calls base64.b64decode(response["content"]). The same content-length quirk applies: the field includes newlines for readability, and forgetting to strip them is a rite of passage.

6. Real-time protocol fallbacks

Socket.IO’s polling transport can’t always carry raw binary safely — long-polling messages historically rode inside JSON text frames — so Engine.IO base64-encodes binary content when the transport can’t carry binary (older polling clients), and the forceBase64 client option forces that path even where raw attachments over XHR2 are possible. Watch ?transport=polling traffic in the network tab: the payload is text that parses as packet-type digits and Base64 chunks. It’s the same 33% tax, paid by every message that takes the base64 path, until a WebSocket upgrade happens.

7. HTTP Basic authentication

The original Authorization header, still running internal APIs everywhere:

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

Decode the value and you find username:password — joined with a colon, then Base64-encoded. For the boilerplate user / user pair on half the sample router configs on the internet, the header is literally Authorization: Basic dXNlcjp1c2Vy.

Why Base64 at all? Header field values were historically constrained to printable US-ASCII, but usernames and passwords may contain arbitrary bytes — including colons and non-ASCII characters. RFC 7617’s fix is the colon-join plus a printable-ASCII wrapper; Base64 smuggles the credentials through a grammar that would otherwise reject them, which is packaging, not protection. One asymmetry matters to parsers: the first colon separates the components, so a password may contain colons but a username may not. And test with curl -u user:user — it generates the header for you, avoiding hand-encoding mistakes.

8. RSS and Atom content islands (not Base64)

Feed readers get this wrong constantly, so let’s be precise: when a feed embeds full HTML, it’s <content><![CDATA[<p>Some <b>rich</b> content</p>]]></content>. An XML CDATA island hands the parser everything between the markers verbatim — no encoding, no scheme, no character escaping needed. Atom’s type="html" variant escapes the markup instead (&lt;p&gt;), which is XML entity escaping, not Base64 either. Paste one of those islands into a decoder and you’ll get back exactly what went in, unchanged — the surest proof it was never encoded.

9. Malware hiding payloads

Base64’s favorite villain role. Obfuscated JavaScript droppers follow a pattern so consistent that security scanners grep for the combo: eval(atob('cGF5bG9hZA==')) — a long Base64 constant, decoded through atob, then executed. The telltale eval(atob( sequence shows up in YARA rules and EDR detections for exactly this reason. Its Windows cousin is PowerShell’s -EncodedCommand flag, which takes Base64 of UTF-16LE, not UTF-8: dwBoAG8AYQBtAGkA is merely whoami with the alternating zero bytes intact. That detail is why every malware analyst pastes encoded PowerShell through a UTF-16LE-aware decoder first — and why a plain UTF-8 decode of such a blob comes out as w.h.o.a.m.i.-style confetti. Python droppers trigger on 'from base64 import b64decode', the pattern scanners look for before the script even runs.

10. Linting inline images

Once a team decides to stop inlining Base64 images, keeping them out becomes a lint problem, and Base64’s alphabet makes it trivially greppable: any url(data: match in a stylesheet is a vote for a data URI that survived cleanup. Stylelint makes the guard a one-liner — a rule or plugin that flags url(data: declarations over a size budget (say, anything beyond a handful of kilobytes) catches the regression the week the cleanup sprint ends, not six months later. The same grep works in CI for any stylesheet, any framework, zero dependencies.

A field kit for all of it

Wherever you meet Base64, three habits cover 95% of the work:

  1. Know your alphabet. Standard (+ /, padded) for email, PEM and XML; URL-safe (- _, unpadded) for URLs, filenames and JWTs.
  2. Know your charset. Base64 carries bytes; something else decided which bytes your text became. When output looks wrong, suspect the charset before the Base64 — and payload framing (the data: prefix, the -----BEGIN----- lines, the .b64decode(content) upstream that double-encoded things) before the charset.
  3. Inspect before trusting. A hex view of the decoded bytes plus automatic type detection tells you whether you have an image, a PDF, UTF-16 PowerShell, or EBCDIC from a mainframe.

Both tools on this site were built around those three habits: the encoder and decoder, all client-side, nothing uploaded, ever.

Try it yourself — right now

Both tools run 100% in your browser. Nothing you type or drop is ever uploaded.

Related posts

esc

Tools

Pages

↑↓ navigate↵ open⌘K

Keyboard shortcuts

Same shortcuts everywhere — ⌘ on macOS, Ctrl on Windows and Linux.