Skip to content
OmniTools

Base64 Encoder & Decoder

Encode text or files to Base64 and decode it back, handling UTF-8 correctly in both directions.

All developer tools

Base64 encoder & decoder

Result

Base64 is an encoding, not encryption. Anyone can decode it, so never use it to protect a password or a token. Encoding adds roughly a third to the size, because 3 bytes become 4 characters.

This tool runs entirely in your browser. Nothing you enter is uploaded, stored, or logged.

What this tool does

Base64 turns binary data into text so it can travel through channels that only handle text: email bodies, JSON fields, URLs, and configuration files. It is an encoding, not encryption — anyone can decode it — which is the single most important thing to understand before using it.

How it works

Base64 works on 3-byte groups. Those 24 bits are split into four 6-bit values, and each value indexes one of 64 printable characters. Because 3 bytes do not divide evenly into 6-bit groups, padding equals signs are added when the input does not end on a full group, which is why Base64 output is always a multiple of 4 characters.

The subtle failure is text encoding. JavaScript strings are UTF-16, and the standard browser atob and btoa functions treat them as Latin-1, so any character above U+00FF throws or silently corrupts. This tool encodes through a UTF-8 byte array, so accented letters, emoji, and non-Latin scripts round-trip correctly instead of producing mojibake.

For files, the bytes are read directly rather than being forced through a string, and the output can be wrapped as a data URI with the correct MIME type. That is what makes an image embeddable in CSS or a self-contained HTML file.

Worked example

Embedding a small icon directly in a CSS file as a data URI.

  1. Read the file bytes
  2. Encode to Base64
  3. Prefix with data:image/png;base64,
  4. Use as background-image: url(...)

A self-contained stylesheet with no extra network request. The trade-off is that the file grows by roughly a third, since Base64 uses 4 characters for every 3 bytes.

Accuracy and limitations

  • Base64 is not encryption. It is trivially reversible and must not be used to protect passwords, tokens, or personal data.
  • Base64 increases size by about 33%, which matters when embedding assets.
  • Decoding input that is not valid Base64, or that has whitespace inserted, may fail. Remove line breaks first if the data was wrapped.

Frequently asked questions

Is Base64 encryption?
No. It is an encoding that exists so binary data can pass through text-only channels. There is no key and no secret, so anyone who has the string can decode it in one step. Use real encryption for anything that needs protecting.
Why does my emoji or accented text decode incorrectly?
Usually because the encoder treated the string as Latin-1 rather than UTF-8. The browser's built-in btoa only handles code points up to U+00FF. This tool converts to UTF-8 bytes first, so non-Latin text and emoji round-trip correctly.
Why does Base64 end in equals signs?
The encoder works in 3-byte groups producing 4 characters. When the input does not fill the last group it pads with one or two equals signs so the length stays a multiple of 4. The padding carries no data.
Can I encode an image?
Yes. Choose the file option rather than the text option so the bytes are read directly, and tick the data URI option if you need the complete data:image/... prefix for embedding in CSS or HTML.