Base64 and URL percent-encoding solve two different transport problems, yet they show up side by side in HTTP headers, query strings, JWTs, webhooks and inline images. Understanding how each encoding works — and where they trip up real code — saves hours of debugging. You can test every example below offline in the Encoder / Decoder.
How Base64 works (and why it adds 33%)
Base64 turns arbitrary binary bytes into plain printable ASCII so data can travel safely through text-only formats like JSON, XML, email bodies and HTTP headers.
Every 3 input bytes (24 bits) are split into 4 groups of 6 bits, and each 6-bit value (0–63) maps to one of 64 characters: A–Z, a–z, 0–9, +, and /. When the input length is not a multiple of 3 bytes, Base64 appends = or == padding at the end.
| Input | UTF-8 Bytes | Base64 Output |
|---|---|---|
Hi | 48 69 (2 bytes) | SGk= |
Helpy | 48 65 6c 70 79 (5 bytes) | SGVscHk= |
{"ok":true} | 11 bytes | eyJvayI6dHJ1ZX0= |
Because 3 bytes always expand to 4 characters, Base64 payloads are roughly 33% larger than the raw binary bytes (plus any line wrapping or padding).
Standard Base64 vs URL-safe Base64
Standard Base64 uses +, /, and =, which all have special meaning in URLs: + is often decoded as a space in form queries, / splits path segments, and = separates query keys from values.
URL-safe Base64 (RFC 4648 §5) solves this with two character swaps and optional padding removal:
| Standard Base64 | URL-safe Base64 |
|---|---|
+ | - (hyphen) |
/ | _ (underscore) |
= padding required | = padding usually omitted |
JSON Web Tokens use unpadded URL-safe Base64 for both their header and payload segments. If you are inspecting a token, you can decode raw segments in Encoder / Decoder or verify full signatures and claims in the JWT Decoder & Builder.
Base64 Data URIs for inline assets
A Data URI embeds a small file directly inside HTML, CSS, or JSON using the format:
data:<mime-type>;base64,<encoded-bytes>
For example, a tiny 1×1 transparent PNG is only ~90 characters as a Data URI, avoiding an extra HTTP round trip. Larger photos, however, pay the 33% Base64 size penalty and cannot be cached separately from the HTML or CSS bundle that contains them.
Rule of thumb: inline tiny icons (under ~2 KB) or single-file standalone exports; keep larger images as separate compressed files via the Image Converter. To generate a Data URI from any local file (up to 5 MB), click Load in Encoder / Decoder and tick Data URL.
URL percent-encoding (%20 vs +)
URL encoding protects reserved URI characters (?, &, =, #, /, %, spaces and non-ASCII text) by replacing each UTF-8 byte with % followed by two uppercase hex digits — for example, a space becomes %20 and & becomes %26.
In JavaScript, the most common bug is picking the wrong built-in function:
| Function | Encodes / ? & = #? | When to use |
|---|---|---|
encodeURI(url) | No | Encoding a full URL while keeping its structure intact |
encodeURIComponent(val) | Yes | Encoding a single query parameter value or path segment |
URLSearchParams | Yes (spaces → +) | Building application/x-www-form-urlencoded query strings |
Watch out for +: in application/x-www-form-urlencoded forms (URLSearchParams), + represents a space, whereas in URL paths and decodeURIComponent(), + stays a literal plus sign.
Five common encoding mistakes
- Treating Base64 as encryption. Base64 has no secret key — anyone can reverse it in milliseconds. Never rely on it to hide credentials, tokens, or personal data.
- Double-encoding URLs. Running
encodeURIComponenttwice turns%20into%2520, breaking downstream parsers. - Breaking UTF-8 with
btoa()in JavaScript. Browserbtoa()only accepts Latin-1 code points (0–255) and throws on emoji or accented Unicode unless you encode viaTextEncoderfirst. - Ignoring whitespace or missing
=padding. Logs and emails often wrap Base64 at 76 characters or strip trailing=; lenient decoders normalise both before decoding. - Pasting production secrets into server-backed decoders. Decoding a Base64-encoded
.env, Kubernetes secret, or Basic Auth header on a hosted site sends that secret to someone else's logs.
Decode and chain payloads privately
HelpyTools' Encoder / Decoder runs entirely in your browser: paste a string and it automatically detects Base64, URL encoding, HTML entities, hex, binary, Base32, or Unicode escapes, previews decoded images, and lets you download decoded binary files.
When a decoded Base64 string turns out to be JSON or an HTTP header, click Send to ▾ to pass the output straight into the JSON Formatter, HTTP Analyser, or Hash Generator without leaving your browser.