MultiTools
Text & Data

Base64 Encoder

Encode and decode Base64 without uploading data.

  • Local by default
  • No signup
  • AI is opt-in

Encode a file

Useful for data URLs and API payloads. Files are read locally and never uploaded.

Base64 turns arbitrary bytes into text that survives systems expecting printable ASCII. It is not encryption, and it is not compression — it makes data larger. Encode or decode text and files here, with correct UTF-8 handling and the URL-safe alphabet.

What Base64 actually does

Base64 groups input bytes into threes (24 bits) and emits four characters (6 bits each) from a 64-character alphabet: A–Z, a–z, 0–9, + and /. Because 3 bytes become 4 characters, encoded output is exactly 33% larger before padding. If the input length is not a multiple of three, = padding characters fill the final group.

That is the whole format. There is no key, no salt and no transformation you can reverse without the original bytes — which is why "decoding" Base64 is a single deterministic step that anyone can perform.

A hand-checkable example

The classic test vector is the ASCII word Man. Its three bytes are 4D 61 6E, which split into four six-bit groups and map to TWFu. Shortening the input shows where padding comes from: two bytes produce three characters and one =, while one byte produces two characters and two.

"Man" → 4D 61 6E → TWFu
"Ma"  → 4D 61    → TWE=
"M"   → 4D       → TQ==

If a decoder rejects a string that looks correct, compare its length to this pattern. Standard Base64 is always a multiple of four characters after whitespace is removed, and padding is only valid at the end.

Base64 is not encryption

This deserves its own section because it causes real incidents. Base64 offers zero confidentiality: anyone who sees the string can decode it instantly. Encoding a password, an API key or a session token in Base64 and calling it protected is equivalent to leaving it in plain text with extra steps. Use encryption (AES-GCM, libsodium) for confidentiality and TLS for transport; Base64 is only about making bytes text-safe.

The URL-safe alphabet

Standard Base64 uses + and /, which have meaning inside URLs and file paths. The URL-safe variant replaces them with - and _, and usually drops the = padding. JWTs, many API signatures and most modern token formats use this variant. Mixing the two is a classic bug: a token decoded with the wrong alphabet produces garbage or throws.

standard:  SGVsbG8/Pz8=
url safe:  SGVsbG8_Pz8

Where you meet Base64 every day

  1. HTTP Basic authentication — Authorization: Basic base64(user:password). It is encoding for header safety, not protection; without TLS the credentials are effectively plain text.
  2. Email attachments — MIME wraps Base64 at 76 characters per line.
  3. JSON binary fields — APIs that cannot carry raw bytes send Base64 strings instead.
  4. Data URLs — inline images and fonts in HTML or CSS.
  5. JWTs — Base64URL segments, with padding removed.

Compression and size

Base64 never makes data smaller. If a payload is too large, compress the raw bytes first and encode the compressed result; encoding first defeats the compressor because Base64 output has little redundancy left. For images, prefer a normal file URL or multipart upload over a data URL once the asset passes a few kilobytes.

Unicode: why btoa throws on emoji

The browser’s btoa function accepts only Latin-1 characters, so it fails on emoji and most non-English text. The correct pipeline is: string → TextEncoder (UTF-8 bytes) → Base64. Decoding runs the reverse: Base64 → bytes → TextDecoder("utf-8"). Skipping the UTF-8 step is why some generators produce 4pyT and others throw. This tool always goes through UTF-8.

Data URLs and when not to use them

A data URL embeds a resource directly in a document: data:image/png;base64,iVBOR…. It removes a request for tiny icons, but the 33% overhead plus base64’s poor compressibility usually makes it worse for real images. It also blocks HTML parsing and cannot be cached separately. For files above a few kilobytes, serve them normally.

Common mistakes

  1. Double encoding. Encoding an already-encoded string produces valid-looking output that decodes to the previous Base64, not the original text.
  2. Stripping padding. Some decoders accept unpadded input, many do not. If a third-party API rejects your string, padding is the first thing to check.
  3. Embedded newlines. MIME-style Base64 wraps at 76 characters. Decoders vary in whether they ignore line breaks; strip whitespace before decoding.
  4. Assuming text. Base64 can encode any bytes, including binary. Decoding binary as text produces replacement characters — that is expected, not corruption.

Frequently asked questions

How much larger does Base64 make my data?

Exactly one third larger before padding: 3 bytes become 4 characters. A 1 MB file becomes about 1.33 MB of text. The padding adds up to two extra characters at the end.

Is Base64 secure or encrypted?

No. Base64 is a reversible encoding with no key. Anyone can decode it in one step. Never treat Base64 as protection for secrets — use real encryption for confidentiality and HTTPS for transport.

Why does atob throw "InvalidCharacterError"?

Either the string contains characters outside the Base64 alphabet (whitespace, emoji, or URL-safe - and _ passed to a standard decoder), or its length is not a multiple of four after removing padding. Normalise the alphabet and re-add padding first.

What is the difference between Base64 and Base64URL?

Only two characters and the padding: Base64URL uses - and _ instead of + and /, and usually omits =. It exists so tokens can be embedded in URLs, filenames and JSON without escaping.

Can I encode large files here?

Yes, with a practical limit. The browser holds the file and the encoded string in memory at the same time, so files beyond roughly 100 MB can freeze the tab. For anything that large, use a command-line tool.

Why does HTTP Basic auth use Base64?

It encodes the username and password so they can travel in an HTTP header without spaces or control characters. It is not encryption and adds no security; HTTPS is what protects the credentials in transit.

Does Base64 compress data?

No, it expands data by about one third. If you need smaller payloads, compress the raw bytes first (gzip, brotli or zstd) and then Base64-encode the result, because compressing Base64 text is much less effective.