Base64 encoding converts binary data to ASCII text using 64 safe characters. It's everywhere — JWTs, email attachments, CSS data URIs, HTTP auth headers — but it's also frequently misused.
What Base64 Does
Every 3 bytes of input become 4 characters of output. That's a 33–37% size increase. Always.
| Original | Base64 Encoded | Size Increase |
|---|---|---|
| 1 KB | ~1.37 KB | +37% |
| 10 KB | ~13.7 KB | +37% |
| 100 KB | ~137 KB | +37% |
The = padding at the end means input length wasn't divisible by 3.
Use Cases
Embed images in HTML/CSS — small icons under 5 KB save an HTTP request.
JWTs — use Base64URL (replaces + with -, / with _). The header and payload are not encrypted — anyone can decode them.
HTTP Basic Auth — Authorization: Basic dXNlcjpwYXNz is just user:pass encoded. Only safe over HTTPS.
Email attachments (MIME) — binary content encoded as text for text-based mail protocols.
When NOT to Use Base64
Not encryption. atob('aGVsbG8=') returns hello instantly. Never use Base64 to "hide" sensitive values.
Not for large images. A 100 KB photo becomes 137 KB in Base64. Use external files.
Quick Code Reference
``javascript
// Browser
btoa('hello') // encode
atob('aGVsbG8=') // decode
// Node.js
Buffer.from('hello').toString('base64')
Buffer.from('aGVsbG8=', 'base64').toString()
`
<code>python
<p>import base64</p>
<p>base64.b64encode(b'hello') # b'aGVsbG8='</p>
<p>base64.b64decode('aGVsbG8=') # b'hello'</p>
</code>`
For one-off encoding/decoding, use a browser-based Base64 tool — nothing gets uploaded, runs entirely in browser.
Originally published at https://snappytools.app/base64-encoder-decoder/