Base64 Encode / Decode

Turn text or any file into Base64, or decode a Base64 string back into readable text or a downloadable file. Accented letters and emoji are handled correctly as UTF-8.

Mode

Encoding and decoding happen inside your browser. Your text and files are not uploaded to our server.

How to use the Base64 Encode / Decode

  1. Choose a mode: encode text, decode Base64, or encode a file.
  2. For text, type or paste into the box; the result updates as you type. Tick URL-safe if the output will go into a URL, a file name or a JSON Web Token.
  3. To decode, paste the Base64 string. Line breaks and spaces are ignored, missing = padding is added for you, and a full data: URL is accepted too.
  4. If the decoded data is an image, PDF or other binary file, use Download decoded file to save it.
  5. For a file, drop it on the box and choose plain Base64 or a data URL you can paste into HTML or CSS.

How Base64 works

Base64 represents binary data using 64 safe characters: A–Z, a–z, 0–9, plus + and /. Every 3 bytes of input (24 bits) are split into four 6-bit groups, and each group becomes one character. That is why Base64 output is about a third larger than the original: 3 bytes in, 4 characters out. When the input length is not a multiple of 3, the output is padded with one or two = signs.

Base64 is an encoding, not encryption. Anyone can decode it, so never use it to hide passwords or personal data.

Text, UTF-8 and the "Latin1" error

The browser's built-in btoa() function only accepts characters that fit in a single byte, and throws an error on anything outside the Latin1 range, such as "ő", "€" or an emoji. This tool first converts your text to UTF-8 bytes with TextEncoder and then encodes those bytes, so any language works. When decoding, the bytes are read back as UTF-8. If they are not valid UTF-8, the tool does not show garbled characters; it tells you the data is binary, guesses the file type from its first bytes where it can (PNG, JPEG, GIF, WebP, PDF, ZIP, gzip) and lets you download it.

URL-safe Base64

RFC 4648 defines a variant for URLs and file names that uses - instead of + and _ instead of /, since those two characters have special meanings in URLs. The padding is often left off when the length is known. JSON Web Tokens use this form. The decoder here accepts both alphabets automatically, with or without padding.

Frequently asked questions

Are my files uploaded when I encode them?

No. The file is read by your browser with the FileReader API and encoded on your device. Nothing is sent to our server.

Why does decoding show "binary data" instead of text?

The decoded bytes are not valid UTF-8 text, or they contain control characters, which usually means the Base64 holds an image, a PDF or another file. Use Download decoded file to save it; the file type is guessed from its first bytes when possible.

What is a data URL?

It is a way of embedding a file directly in HTML or CSS, in the form data:image/png;base64,iVBOR…. It saves a separate request for very small images and icons, but makes your page larger, so it is not a good idea for big images.

My Base64 string has line breaks every 76 characters. Is that a problem?

No. MIME, the format behind email attachments, limits Base64 lines to 76 characters, so wrapped Base64 is common. The decoder ignores all whitespace, including line breaks.

Is there a size limit?

Only your device's memory. Very long results (over two million characters) are not displayed in the box, to keep the page responsive, but you can still copy or download them.

Sources: RFC 4648: The Base16, Base32, and Base64 Data Encodings; web.dev: The nuances of base64 encoding strings in JavaScript

Related tools