Back to Home

Base64 Encoder / Decoder

Encode and decode text or files to and from Base64

About This Tool

Encode text or files to Base64 and decode Base64 back into readable text, with UTF-8 support and a ready-made data URI for uploaded files.

What this Base64 tool does

Base64 turns arbitrary bytes into a string made only of letters, digits, +, / and =. That makes binary data safe to place in places that only expect text: JSON payloads, email bodies, HTML attributes, environment variables or HTTP headers. This page lets you encode plain text, decode a Base64 string back to text, and convert any file into Base64 along with a complete data URI. Encoding and decoding are done by your browser, and files you select are read locally rather than uploaded.

How to use it

Text mode

  1. Keep the Text tab selected.
  2. Choose Encode to turn text into Base64, or Decode to turn Base64 back into text.
  3. Type or paste into the input box and press Encode to Base64 or Decode from Base64.
  4. Copy the result from the Output box.

File mode

  1. Switch to the File tab and click the upload area to pick a file.
  2. The Output box shows the raw Base64 string, and a Data URI box shows the same data prefixed with its MIME type, for example data:image/png;base64,....
  3. If the file is an image, a preview appears so you can confirm you picked the right one.

How Base64 encoding works

Computers store data in 8-bit bytes. Base64 takes the input three bytes at a time, which is 24 bits, and splits those 24 bits into four groups of 6 bits. Each 6-bit group has 64 possible values, and each value maps to one character in the Base64 alphabet: A to Z, a to z, 0 to 9, then + and /. When the input length is not a multiple of three, the output is padded with one or two = signs.

Because every 3 bytes become 4 characters, encoded output is about 33% larger than the original. A 30 KB image becomes roughly 40 KB of Base64 text. That overhead is why Base64 suits small assets and short tokens, not large files.

For text, the tool first converts your characters to UTF-8 bytes, so accented letters, non-Latin scripts and emoji encode correctly instead of throwing the error that plain btoa() produces for non-ASCII input. Decoding reverses the process and expects the bytes to be valid UTF-8 text.

Common uses

  • Embedding a small icon or logo directly in CSS or HTML using the data URI.
  • Reading the payload of a token or config value that was stored as Base64.
  • Building HTTP Basic Authentication headers, which encode username:password in Base64.
  • Pasting binary test fixtures into JSON or YAML files.

Things to watch out for

  • Base64 is not encryption. Anyone can decode it in one step. Never use it to hide passwords or secrets.
  • Remove the data URI prefix before decoding. The text decoder expects only the Base64 part, not data:...;base64,.
  • URL-safe Base64, which uses - and _ instead of + and /, is not accepted directly. Swap those characters back before decoding.
  • Text decoding is meant for strings that represent text. To turn Base64 back into a picture, use the dedicated Base64 to image tool.

FAQ

Why does my decoded output say the string is invalid?

Usually the input contains characters outside the Base64 alphabet, such as a data URI prefix, URL-safe characters, or a truncated end. It can also mean the data decodes to binary bytes rather than UTF-8 text.

Should I inline every image as Base64?

No. The 33% size increase and loss of browser caching make it worthwhile only for very small images. For converting pictures specifically, the image to Base64 tool is a focused alternative.

What do the equals signs at the end mean?

They are padding that brings the output to a multiple of four characters when the input was not a multiple of three bytes.