Toolvito

Works on this device

Base64 Encoder & Decoder

Turn text into Base64, or turn Base64 back into text or bytes. The work is done in your browser: the text you type is not sent to a server.

Your text

Every character counts, also spaces and line breaks at the start and the end.

How characters become bytes. UTF-8 is the usual choice.

More options

A text box holds each line break as one LF byte (0A).

Your text is converted in this browser. It is not sent to a server.

The result will show here

Type or paste some text, or choose Try an example.

How to use the Base64 encoder and decoder

  1. Choose what to do in the menu: encode text, decode Base64, check Base64, make a data URL or read a data URL.
  2. Type or paste your text. The result shows as you type. You can also open a text file from your device.
  3. For encoding, choose the alphabet. The standard alphabet uses + and /. The URL-safe alphabet uses - and _, so the result can go into a web address or a file name.
  4. For decoding, the page is strict. It stops at the first wrong character and tells you its place. Tick Ignore spaces and line breaks for Base64 that is split into lines, and Accept missing padding (=) for values without = at the end.
  5. Choose Copy output or Download output to keep the result.

How Base64 works

Base64 writes bytes with 64 safe characters: A to Z, a to z, 0 to 9 and two more signs. Each character holds 6 bits, so every 3 bytes (24 bits) become 4 characters. The output is about one third longer than the input.

When the last group has only 1 or 2 bytes, the output ends with == or =. This is called padding. It keeps the length a multiple of 4.

Base64 is an encoding. It is not encryption and it has no key. Anyone can decode it, so it does not keep a password or a secret safe.

This page follows RFC 4648: section 4 for the standard alphabet and section 5 for the URL-safe alphabet.

Worked example

The text Hello, world! is 13 bytes in UTF-8. Its Base64 is SGVsbG8sIHdvcmxkIQ==: 20 characters, and two of them are padding.

The three letters foo are the bytes 66 6F 6F. In bits that is 011001 100110 111101 101111, which are the values 25, 38, 61 and 47. The alphabet gives Zm9v.

The three bytes FB FF FE give +//+ in the standard alphabet and -__- in the URL-safe alphabet.

Text, bytes and encodings

  • Base64 works on bytes, not on letters. Text must first become bytes, and the text encoding says how. UTF-8 is the usual choice and covers every language and emoji.
  • In UTF-8 the letter é is the two bytes C3 A9, and the emoji 😀 is four bytes. In ISO-8859-1 the letter é is the single byte E9. The same text gives different Base64 in different encodings.
  • When you decode, choose the encoding that the sender used. If the bytes are not valid text in that encoding, the page names the first wrong byte. It does not swap wrong bytes for other characters unless you tick the option for that.
  • If the Base64 holds a file such as a picture, it is not text. Choose bytes in hexadecimal to see the bytes, or use Check Base64 and see what it holds.

Data URLs

A data URL holds a small file inside a web address: data: then the media type, then ;base64, and the Base64 of the file. An example is data:text/plain;charset=UTF-8;base64,SGVsbG8sIHdvcmxkIQ==.

Make a data URL builds one from text you type, or from Base64 that you already have. It can also write an HTML img tag or a CSS url() value. Read a data URL shows the media type and the data inside. Data URLs follow RFC 2397.

The same result in code

These standard functions give the same Base64 as this page. Most of them work on bytes, so turn your text into UTF-8 bytes first.

Base64 functions in common languages
Language Encode Decode
Python base64.b64encode(data) base64.b64decode(text)
JavaScript in a browser btoa(text), only for characters up to U+00FF atob(text)
Node.js Buffer.from(text, "utf8").toString("base64") Buffer.from(text, "base64").toString("utf8")
PHP base64_encode($data) base64_decode($text, true)
Java 8 and later Base64.getEncoder().encodeToString(bytes) Base64.getDecoder().decode(text)
Go base64.StdEncoding.EncodeToString(data) base64.StdEncoding.DecodeString(text)
Ruby Base64.strict_encode64(data) Base64.strict_decode64(text)
C# Convert.ToBase64String(bytes) Convert.FromBase64String(text)
PostgreSQL encode(data, 'base64') decode(text, 'base64')
MySQL TO_BASE64(data) FROM_BASE64(text)
OpenSSL command openssl base64 -e openssl base64 -d

Limits you should know

  • This page reads and writes text only. It does not open a PDF, a picture, a video or another binary file, and it does not save decoded bytes as such a file. For pictures, use the Image Encoding Converter.
  • A text file is opened as text. Windows line ends (CR LF) become LF and a byte order mark is removed, so the Base64 can differ from the Base64 of the exact bytes of the file. Under More options you can ask for CR LF line ends.
  • The text to encode can have up to 1,000,000 characters. Base64 to decode and data URLs can have up to 2,000,000 characters, which is about 1.5 MB of data.
  • The check of what Base64 holds looks at the first bytes only. It knows a short list of file types: PDF, PNG, JPEG, GIF, WebP, WAV, ZIP, gzip, MP4, MP3, Ogg, WebM, WOFF and WOFF2.
  • Windows-1252 has five byte values with no character (81, 8D, 8F, 90 and 9D). This page treats them as errors. Some browsers show them as control characters.
  • Other encodings such as Base32 and Base58 have their own tool on this site, and so do hashes, JSON Web Tokens and QR codes.

Related tools