toolqik

76 · Encode & Convert

Base64 Encoder / Decoder

UTF-8-safe Base64 and Base64URL, for text and files.

Runs in your browser
Mode
Options
Output

  

About this tool

Base64 turns any data (text, images, keys, files) into plain text made of 64 safe characters: A–Z, a–z, 0–9, + and /. That lets binary data travel through places built for text, like JSON, HTML, email, URLs and HTTP headers. This Base64 encoder and decoder handles both directions, works with any language including emoji, and runs entirely in your browser.

How to use it

  1. Choose Encode (text to Base64) or Decode (Base64 to text).
  2. Paste your input. With Convert as I type on, the result updates as you type. Large inputs (over 1 MB) are converted when you press Ctrl+Enter or change a setting.
  3. Turn on URL-safe to get Base64URL output, as used in JWTs and URLs. When decoding, both alphabets are accepted, padding is optional, line breaks are ignored, and you can paste a whole data: URL.
  4. Use the swap button (⇄) to feed the output back in as input, or Encode a file to turn an image or other file into a data URL.

If decoded data isn’t text (an image, a PDF, a ZIP), you get a hex preview and Download saves the original bytes.

How Base64 works

Base64 takes the input 3 bytes at a time (24 bits) and writes them as 4 characters of 6 bits each. So Man becomes TWFu. When the input isn’t a multiple of 3 bytes, the output is padded with =: Ma becomes TWE=, and M becomes TQ==. That’s why Base64 strings often end in one or two equals signs, and why encoded data is about 33% larger than the original.

Text is first turned into bytes using UTF-8. That’s what lets héllo 👋 survive the round trip as aMOpbGxvIPCfkYs=, and it’s the step that JavaScript’s plain btoa() skips.

Base64 vs. Base64URL

Base64 (standard)Base64URL
Characters 62 and 63+ and /- and _
Padding= at the endUsually omitted
Safe in URLs and file namesNo (+, / and = have special meanings)Yes
Used byEmail (MIME), data URLs, HTTP Basic auth, PEM keysJWTs, OAuth PKCE, many web APIs

Where you’ll see Base64

  • Data URLs: data:image/png;base64,iVBORw0… embeds an image directly in HTML or CSS. Good for small icons; for large images a normal file is faster.
  • HTTP Basic authentication: Authorization: Basic dXNlcjpwYXNz is just user:pass in Base64. Anyone who sees the header can decode it, so only use it over HTTPS.
  • JWTs: the header and payload are Base64URL-encoded JSON. Read them with the JWT decoder.
  • Kubernetes secrets and config files: values are stored as Base64, which keeps binary data intact but does not hide it.
  • Email attachments, PEM certificates and keys: Base64 split into lines of 64 or 76 characters.

Base64 encode and decode in code

// btoa()/atob() only handle Latin-1, so go through UTF-8 bytes first
function encodeBase64(text) {
  let binary = '';
  for (const byte of new TextEncoder().encode(text)) binary += String.fromCharCode(byte);
  return btoa(binary);
}

function decodeBase64(base64) {
  const bytes = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
  return new TextDecoder().decode(bytes);
}

encodeBase64('héllo 👋'); // "aMOpbGxvIPCfkYs="

Troubleshooting

  • “The string to be encoded contains characters outside of the Latin1 range” (InvalidCharacterError from btoa): your text has characters like emoji or accents. Encode it to UTF-8 bytes first, as in the JavaScript example above.
  • “Incorrect padding” in Python: the input has no = padding, as in Base64URL. Add = until the length is a multiple of 4, or use this tool, which doesn’t need padding.
  • “Invalid character” when decoding: the input is URL-safe Base64 (- and _), or it has been URL-encoded (%2B, %3D). Decode it with the URL decoder first.
  • Strange characters such as é in the result: the text was encoded with one character set and decoded with another. This tool always uses UTF-8.

FAQ

How do I decode Base64?

Select Decode and paste the Base64 string. The text appears instantly. If the data is a file such as an image, you can download the original bytes.

Is Base64 encryption?

No. Base64 is an encoding, and anyone can decode it. Never use it to hide secrets.

Why does Base64 end with = or ==?

Base64 encodes 3 bytes as 4 characters. If the input length is not a multiple of 3, one or two = signs pad the output to a multiple of 4 characters.

How much bigger does Base64 make data?

About 33%: every 3 bytes become 4 characters. 1 MB of data becomes roughly 1.33 MB of Base64, plus line breaks if the format adds them.

Why does decoding show "binary data"?

The decoded bytes are not valid UTF-8 text (for example, an image or compressed file). You can still download the raw bytes.

Can I convert an image to a data URL?

Yes. Use "Encode a file" and the output will be a data: URL you can paste into CSS or HTML.

What is the difference between Base64 and Base64URL?

Base64URL replaces + and / with - and _ and usually drops the = padding, so the result is safe in URLs and file names. JWTs use Base64URL.

Is my data uploaded?

No. Encoding and decoding run in your browser, in a background worker, and nothing is sent to a server.

esc
↑↓ navigate↵ open