Base64, HTML Entities & Encoding for Developers (2026)
Base64, HTML entities and URL encoding with measurements: Base64 adds 33.3% to 33.6% depending on size, and Chromium's HTML parser shows which unescaped characters really break a page, including an ampersand that turned "© right" into "© right".
Base64: What It Costs
Base64 turns every 3 bytes into 4 printable characters from a 64-character alphabet (RFC 4648), so text-only channels such as email bodies, JSON and data URIs can carry binary data. The price is size. Encoding random data of three sizes gave:
| Input | Base64 | Overhead |
|---|---|---|
| 1,000 bytes | 1,336 characters | 33.6% |
| 10,000 bytes | 13,336 characters | 33.4% |
| 100,000 bytes | 133,336 characters | 33.3% |
The overhead settles at a third, plus up to two padding characters. Gzip on the page wins some of it back, but the file can no longer be cached on its own, so inline only small images that every visit needs, such as an icon in critical CSS. URL-safe Base64 (Base64url) swaps + and / for - and _ so tokens survive in URLs; JSON Web Tokens use it.
HTML Escaping: What Actually Breaks
Advice often says five characters must always be escaped. We parsed each case with Chromium's own HTML parser to see what really changes the result:
| Written as | Where | What the parser produced |
|---|---|---|
5 > 3 | text | unchanged |
Tom & Jerry | text | unchanged |
AT&T | text | unchanged |
© right | text | became © right |
©right | text | became ©right |
a <b c | text | became an element; text cut to a |
He said "hi" | text | unchanged |
a "b" c | double-quoted attribute | became a |
So in text, < must always be escaped, and & must be escaped whenever letters follow it: the parser still decodes old named references without a semicolon, so "© right" silently became "© right". Inside an attribute, escape the quote character that delimits it. > and quotes in plain text are harmless, but escaping all five everywhere is the simple rule that never fails, and it is what our HTML Entity Encoder does by default; its decoder matched Python's html.unescape on 12 of 12 test strings.
URL Encoding
Percent-encoding writes a byte as % plus two hex digits; non-ASCII text is first turned into UTF-8 bytes, so "é" becomes %C3%A9. In JavaScript, encodeURIComponent() is for one value (a query parameter or path segment) and encodeURI() for a whole URL, which it leaves usable by not touching / ? & =. Our URL encoding guide compares encoders and how live servers treat the different spellings.
Our Encoding Tools, Tested
- Base64 Tool: reports real file sizes, re-encodes to URL-safe on the fly, and shows bytes that are not text as a hex dump with a download instead of an error; its output matched Python's base64 module.
- Image to Base64: builds data URIs; note that Gmail and Outlook for Windows (2007 to 2016) do not display Base64 images in email, per caniemail data.
- Hash Generator: MD5 and SHA-family digests over UTF-8 bytes, matching Python's hashlib on 12 of 12 test inputs.
- URL Encoder: component and full-URL modes.