About Base64 Encoder / Decoder
Base64 is most often used not for secrecy but to squeeze binary data through a text-only channel: inlining an image into a CSS data URI, embedding a certificate or key in a config file, pasting a binary log excerpt into a chat window, or building an HTTP Basic Authorization header. Whenever a place only accepts letters, digits and punctuation, this is the usual bridge. The encoding itself regroups every 3 input bytes (24 bits) into 4 six-bit units mapped through a fixed 64-character alphabet, padding with = when fewer than 3 bytes remain. Because only padding bits are added, the output is about 133% of the original size, which matters when people inline large images as data URIs and inflate the page. Practical notes: The standard alphabet includes + and /, which must be swapped for - and _ (the URL-safe variant) before appearing in a path or query parameter, or the URL will be parsed incorrectly. Non-ASCII text such as Chinese must be UTF-8 encoded before Base64; if the other side decodes as GBK you get mojibake. When decoding, decide whether the result is UTF-8 text or an actual binary file, because the latter should be saved as a file rather than displayed as a string. Limits: Base64 is not encryption: anyone can decode it, so base64-encoding a password, token or national ID protects nothing. The standard does not mandate line breaks, yet many implementations insert one every 76 characters, so cross-system handoffs must agree on wrapping. The trailing = is treated as optional in some implementations, which means it must not be used as an integrity check. Finally, a data URI such as data:image/png;base64, needs the prefix stripped before decoding. Data and privacy: what people encode is typically keys, private certificates, signed tokens or exported personal data, where a leak costs far more than a format conversion is worth. This tool encodes and decodes in the browser without uploading anything. For private keys, the safer routine is to disconnect the network first and confirm the Network panel stays empty throughout. A few implementation details that get overlooked. The btoa function browsers expose only handles Latin-1, so passing Chinese throws InvalidCharacterError: encode to UTF-8 bytes first and convert byte by byte, and annotate any hand-rolled encoding or reliance on encodeURIComponent so the next person does not break it. On size, Base64 is roughly a third larger than the original, which makes it counterproductive as a "compressed transport"; if you genuinely need compression, gzip or Brotli first and Base64 the result. For bulk work, files beyond tens of megabytes must be read in chunks in the browser, since reading them whole consumes large amounts of memory and can crash the page. Finally, some legacy systems expect the + and / alphabet while URLs and filenames require - and _, so agree on the variant before integration rather than debugging why a parameter was parsed as two. For context, note how it divides work with neighbouring encodings: percent-encoding puts arbitrary characters into a URL, hex renders bytes readable, and Base64 fits bytes into a text channel. Each suits a different situation, and mixing them degrades both size and readability. When storing encoded output for the long term, record which variant (standard or URL-safe) and whether it is wrapped, because a missing note on those two points breaks integrations more often than the encoding itself. So the other side does not fall back to a default assumption.
How It Works Internally
Encoding regroups every 3 bytes (24 bits) into 4 six-bit units mapped through a fixed alphabet, padding with equals signs when fewer than 3 bytes remain. Output length is therefore always a multiple of four, which explains why the result is about a third larger than the original. Decoding is the inverse and needs no key or verification.
oltoolb2x0b29sMeasured on This Page
| Encoding | All seven inputs match Python base64 byte for byte, including surrogate-pair characters |
|---|---|
| url-safe | The toggle swaps + and / for - and _ and drops = padding, matching urlsafe_b64encode without padding |
| Decoding leniency | Unpadded input (YQ) and newline-wrapped output from base64 -w 76 both decode correctly |
| Fixed here | Binary bytes such as 0xFF used to report invalid Base64; the string is valid Base64, it just is not UTF-8 text |
| Empty input | Produces no output and no error |
Text mode only handles UTF-8. Pasting the Base64 of a PNG gives bytes that are not text, and the page now says so instead of claiming the Base64 is broken — those are different failures, and the first one means the data is fine and you need the file view or a binary decoder.
How to Use
- Open the Base64 Converter tool
- Choose Encode or Decode mode
- Paste text or upload a file in the input area
- Click the Convert button, results appear in real-time
- Copy the converted result
Use Cases
- Inline images via Data URI — Embed small images as Base64 directly in CSS or HTML to eliminate extra HTTP requests.
- Binary in API payloads — JSON has no binary type, so files and crypto results are commonly transmitted as Base64 strings.
- Debug JWTs — JWTs are three Base64URL segments — decode them individually to inspect header and payload.
- Email attachments — SMTP requires attachments to be Base64-encoded for transport over text-based email.
- Config-file secrets — Certificates and keys are often stored as Base64 in YAML or JSON configuration files.
- Binary data debugging — Decode Base64 strings from API responses to inspect the raw binary content they actually contain.
- JWT segment decoding — Decode each Base64URL segment of a JWT separately to examine the header, payload, and signature sections.
FAQ
Is Base64 encryption?
No. Base64 is encoding — anyone can decode it instantly. For confidentiality, use AES (see our AES Encryption tool).
Why does encoded data get larger?
Base64 uses 4 characters to represent 3 bytes, an ~33% size increase — the cost of squeezing arbitrary binary into a text channel.
What's the difference between Base64 and Base64URL?
Base64URL replaces + and / with - and _, and drops the = padding, making it safe in URLs and filenames. JWTs use Base64URL.
Why does decoding fail?
Common causes: (1) non-Base64 characters like newlines or spaces; (2) missing = padding; (3) URL-safe variant not converted back to + and /.
Can I encode images?
Yes — read the image as a binary Blob/ArrayBuffer first, then encode. Or use our File to Base64 tool to drag-and-drop directly.
Why do I get garbled output when decoding?
Three common causes. First, the source string is not UTF-8 text but true binary (an image, archive, or crypto result), so decoding it naturally yields mojibake — verify the actual content type first. Second, the input isn't strictly standard Base64: it may contain stray newlines/spaces, or a URL encoder already turned + into space or escaped /, so strip non-Base64 characters before decoding. Third, the decoded text uses a differently-encoded charset than you expected. Debug in order: decide whether the payload is really meant to travel binary through a text channel, clean the input, then decode as Unicode.
Does a line break inside Base64 affect decoding?
Yes. Some encoders and mail protocols insert CR/LF every 76 characters (per RFC 4648's recommended line width), and strict decoders either error out or produce corrupt output when they meet those newlines or spaces. If you pasted Base64 that contains line breaks, remove all ASCII whitespace (\n, \r, space) first, then decode. Most modern languages also reject whitespace in strict mode, so you must clean it with replacement or a regex first. A safe pattern is to filter with [^A-Za-z0-9+/=] before handing the string to the decoder.
Base64 output is a third longer than the input — why?
Base64 encodes 3 bytes into 4 characters, a fixed 4/3 overhead built into the scheme. It exists to carry binary data through text channels, not to shrink anything — compress first, then encode.