What Base64 actually does
Base64 is a binary-to-text encoding scheme that represents binary data using a 64-character alphabet (A–Z, a–z, 0–9, plus '+' and '/'). Every three input bytes (24 bits) are split into four 6-bit groups, and each group maps to one character in the alphabet. The output is therefore about 4/3 the size of the input — a 33% overhead. The padding character '=' is used to make the output length a multiple of four.
Why it exists — text-only transports
Many protocols and storage formats were designed to handle text, not arbitrary binary data. Email (MIME), HTTP headers, JSON, XML, and URL query strings all have characters they cannot safely carry raw. Base64 lets you embed binary blobs (images, certificates, archives, encrypted tokens) inside these text-based contexts without worrying about line endings, control characters, or character encoding.
Common legitimate use cases
- Embedding small images inline in CSS or HTML using data: URLs.
- Encoding the header and payload of JWT (JSON Web Tokens) so they survive HTTP headers.
- Transferring binary attachments through MIME-encoded email.
- Storing binary blobs (small images, signatures) inside JSON APIs.
- Encoding certificates and keys in PEM format (which uses Base64 with a header/footer line).
- Encoding HTTP Basic Authentication credentials in the Authorization header.
Base64 is NOT encryption
This is the most common misconception. Base64 is a reversible encoding — anyone with the encoded string can decode it back to the original bytes instantly, no key required. Using Base64 to 'hide' a password, API token, or any other secret provides zero security. If you need to protect data, use proper encryption (AES-GCM, age, libsodium). Base64 is purely a transport encoding.
URL-safe Base64 and other variants
The standard Base64 alphabet uses '+' and '/', both of which have special meaning in URLs. The URL-safe variant (defined in RFC 4648) replaces them with '-' and '_' respectively, and often omits the '=' padding. JWT uses URL-safe Base64. There are also less common variants: Base64url-no-padding, Base32 (used in DNS and TOTP secrets), and Base58 (used by Bitcoin). Always confirm which variant a system expects before encoding or decoding.
Size overhead and when it matters
Base64 adds a 33% size overhead, plus a small number of bytes for padding. For small payloads this is negligible, but for large files it becomes significant. A 10 MB image encoded as Base64 occupies about 13.3 MB of text. For inline data URLs of large images, this overhead defeats the purpose of bundling. Beyond about 4–8 KB, an external file reference is almost always more efficient.
When NOT to use Base64
- When you control the transport and it already supports binary (HTTP body, WebSocket binary frames, gRPC).
- As a form of obfuscation or 'lightweight encryption'.
- To embed large files inline — the overhead and parse cost outweigh the convenience.
- When the consumer cannot easily decode it (e.g., human-readable logs).
Decoding considerations
Most Base64 decoders are strict about padding and whitespace. If you encounter decoding errors, check for missing '=' padding, line breaks inserted by MIME, or the URL-safe variant being decoded with a standard decoder (and vice versa). When testing, paste the suspect string into a known-good decoder like our Base64 Encoder / Decoder to see what error it reports.