A practical guide for developers
Base64 is a way of representing binary data as plain text. It takes any sequence of bytes — an image, a file, a string — and converts it into a string of 64 printable ASCII characters. The result is safe to include anywhere that only accepts text: JSON fields, HTML attributes, email bodies, HTTP headers, and URLs.
Many systems were designed to handle text, not arbitrary binary data. Email protocols, for example, were originally built to carry plain text messages. When you want to attach an image to an email, you can't just dump raw binary bytes into a text-based protocol — it will get corrupted. Base64 solves this by encoding the binary data as a safe, predictable string of text characters.
The same problem applies to JSON (which has no binary type), HTML (where you want to embed an image directly in the source without a separate file), and HTTP headers (which must be ASCII-safe).
Base64 takes every 3 bytes of input (24 bits) and splits them into 4 groups of 6 bits each. Each 6-bit group maps to one of 64 characters: A–Z, a–z, 0–9, plus + and /. If the input isn't divisible by 3, = padding characters are added at the end.
The result is always about 33% larger than the original. A 100-byte file becomes roughly 133 characters of Base64.
background-image: url('data:image/png;base64,...')Basic dXNlcjpwYXNz is just user:pass encodedStandard Base64 uses + and / which are special characters in URLs. Base64url is a variant that replaces + with - and / with _, making it safe to use in URLs and filenames without percent-encoding. JWTs use Base64url.
No. Base64 is an encoding scheme, not encryption. It provides zero security. Anyone who sees a Base64 string can decode it instantly. Never use Base64 to "hide" sensitive data — use proper encryption for that.
Every mainstream language ships Base64 support in its standard library, so you rarely need to implement the algorithm yourself:
btoa() / atob() for strings, or Buffer.from(data).toString('base64') in Node.jsbase64 module: base64.b64encode(data)java.util.Base64.getEncoder().encodeToString(bytes)encoding/base64, with separate StdEncoding and URLEncoding variantsbase64_encode() and base64_decode()The one gotcha across languages: make sure you're encoding bytes, not a string in the wrong character encoding. Encoding a UTF-8 string as if it were Latin-1, for instance, will silently corrupt any non-ASCII characters before Base64 ever touches them.
A few issues come up repeatedly when developers work with Base64:
+ and / instead of - and _ will fail or produce garbage.= characters and will throw on malformed input; others silently ignore the problem.Does Base64 compress data? No — it increases size by roughly a third. If you need smaller payloads, compress first (e.g. gzip), then encode the compressed bytes.
Can I Base64-encode an entire file, not just a string? Yes — any binary file (image, PDF, zip) can be Base64-encoded the same way as any other byte sequence.
Is my data uploaded anywhere when I use an online Base64 tool? It depends on the tool. DataBench's Base64 tool runs entirely in your browser using JavaScript's built-in encoding functions — your input never leaves your machine.
You can encode and decode Base64 directly in your browser using the DataBench Base64 tool. It runs entirely client-side — nothing is sent to a server.