Base64 Converter

Encode text and files to Base64, in the standard or the URL-safe alphabet, and decode Base64 back to text or to the exact bytes it stands for.

Overview

Base64 writes any data with 64 printable characters, so it can travel through systems that only carry text: e-mail, JSON, HTML, configuration files. Every 3 bytes become 4 characters. The standard alphabet of RFC 4648 is A to Z, a to z, 0 to 9, + and /, with = as padding at the end. The URL-safe alphabet from the same RFC uses - and _ instead of + and /, which have a meaning in addresses and file names, and usually leaves the padding out.

Base64 is an encoding, not encryption. Anyone can decode it; there is no key.

Web interface

Paste text or Base64 into the input; the output updates as you type. Auto works out the direction by itself, Encode and Decode fix it. Alphabet chooses Standard or URL-safe for encoding and is hidden in Decode, because decoding accepts both.

Upload file, or a file dropped onto the input, encodes that file: the output holds its Base64, and a Data URI with the file's type appears below it, with its own copy button. Download saves the current result as base64.txt, decoded.txt, or, for binary data, as decoded. followed by the file type. Clear empties everything and returns to Auto and Standard. Ctrl/ + Enter runs the conversion again.

How Auto decides

Many ordinary strings consist of Base64 characters only: every word of four, eight or twelve letters is valid Base64, and so is a hexadecimal hash. Auto therefore goes by what the input would decode to, in this order:

InputAuto
starts with a data:…;base64, prefix, or contains a PEM blockdecodes
contains anything that is not Base64: a space, a comma, punctuationencodes
decodes to readable UTF-8 textdecodes
is at least 64 characters long, mixes upper and lower case and uses 20 or more different charactersdecodes, as binary data
anything elseencodes

So test is encoded to dGVzdA== although it is valid Base64, because it would decode to three bytes that are not text. SGVsbG8 is decoded to Hello, padding or not. When Auto guesses wrong, Encode and Decode settle it.

What decoding accepts

Base64 rarely arrives as one clean line. Decoding accepts it in the forms it is found in:

  • behind a data URI prefix such as data:image/png;base64,, with or without further parameters
  • inside a PEM block, between -----BEGIN CERTIFICATE----- and the matching -----END line
  • broken into lines, as e-mail and PEM wrap it every 64 or 76 characters; all whitespace is ignored
  • in the URL-safe alphabet, with - and _
  • without the = padding

Encoding writes one unbroken line, in the alphabet selected.

Binary data

What decodes to valid UTF-8 text is shown as text. Anything else, bytes that are not UTF-8 or text with control characters other than tabs and line breaks, is binary data. It is not shown, because showing bytes as text changes them; the line under the output gives its size and type, and Download saves the exact bytes. /w== downloads as the single byte FF.

Recognised by its first bytesDownloaded as
PNG imagedecoded.png
JPEG imagedecoded.jpeg
GIF imagedecoded.gif
WebP imagedecoded.webp
PDF documentdecoded.pdf
ZIP archivedecoded.zip
gzip datadecoded.gz
contents of a PEM blockdecoded.der
anything elsedecoded.bin

Errors

Input that is not Base64 is not decoded. The output stays empty and the line under it says why:

MessageMeaning
"*" is not a Base64 characterThe input contains a character outside both alphabets, named in the message.
= may only appear at the end, as paddingAn = in the middle, as when two Base64 strings were joined.
the length does not fit Base64, one character is missing or extraOne character too many or too few: no valid Base64 has a length of 4n + 1.

No API

There is no API for this tool. Encoding and decoding run in the browser; in a script, use the Base64 support of the language at hand, such as base64 on the command line.

Limits

Files can be up to 10 MB. Pasted text has no limit.

Converting is fast: ten megabytes take under 0.2 seconds in every browser tested. Drawing that much text in the input and output fields is what takes time, and it depends on the browser and the characters. For 10 MB of plain ASCII it took about a second in Chrome and Firefox and 6 to 11 seconds in Safari's engine. Text with accents or emoji is much slower to draw in Chrome: 10 MB of it took 30 to 50 seconds there.

Privacy

Nothing leaves the browser. Files are read locally, the conversion runs on the page, and downloads are created on the spot. Nothing is stored, and Copy writes to the clipboard only when you press it.