Skip to content
tools.best

Browse all tools

Base64 Decoder and Encoder

This Base64 decoder and encoder reads Base64 as text, or switches to Encode to turn text into Base64. It works with UTF-8 and with the URL-safe alphabet.

Runs in your browser. Your text is not sent to a server. Sources: RFC 4648 Updated

Direction
20 characters
13 characters

13 bytes out

How Base64 encoding works: 3 bytes, 4 characters

Base64 takes the bytes three at a time. Three bytes are 24 bits, which are cut into four groups of 6 bits. Each group is a number from 0 to 63 and is written as one character from this alphabet:

0–25: A–Z    26–51: a–z    52–61: 0–9    62: +    63: /

Text is turned into UTF-8 bytes first; the text to hex converter shows those bytes for any text. Decoding reverses the steps and then reads the bytes as UTF-8.

How to encode text to Base64 by hand

Encoding Hi!:

  1. The bytes are 72, 105 and 33. In binary, as text to binary writes them: 01001000 01101001 00100001
  2. Regrouped into sixes: 010010 000110 100100 100001
  3. As numbers: 18, 6, 36, 33. In the alphabet these are S, G, k and h.
  4. Result: SGkh

When the input does not divide by three, the last group is padded: Hi encodes to SGk= and H to SA==.

Diagram of Base64 encoding of "Hi!": the bytes 72, 105 and 33 become 24 bits, cut into the 6-bit numbers 18, 6, 36 and 33, which are the characters S, G, k and h, so the result is SGkh.
Four characters for every three bytes is why Base64 is about a third larger than the data it carries.

Base64 examples: text, JSON, accents and emoji

TextBase64URL-safe
Hello, World!SGVsbG8sIFdvcmxkIQ==SGVsbG8sIFdvcmxkIQ
user:passworddXNlcjpwYXNzd29yZA==dXNlcjpwYXNzd29yZA
{"alg":"HS256"}eyJhbGciOiJIUzI1NiJ9eyJhbGciOiJIUzI1NiJ9
caféY2Fmw6k=Y2Fmw6k
a>b?cYT5iP2M=YT5iP2M
😀8J+YgA==8J-YgA

What the Base64 decoder accepts

  • The standard alphabet and the URL-safe alphabet, also mixed.
  • Missing padding, and line breaks or spaces inside the data.
  • A data:…;base64, prefix, which is ignored.

It reports the first character that is not part of Base64, and a length that cannot be right (a single leftover character can never be decoded).

If the decoded bytes are a picture, the Base64 to image converter shows it and saves it as a file. Text full of percent signs, such as hello%20world, is URL encoding, not Base64: read it with the URL decoder.

Base64 Decoder and Encoder: FAQ

What is Base64 used for?
For carrying bytes through systems that only handle text. Email attachments, images embedded in HTML or CSS as data URLs, and the parts of a JSON Web Token are common examples.
Is Base64 encryption?
No. It is an encoding with no key, and anyone can decode it. A password or token in Base64 is as exposed as one in plain text.
What are the = signs at the end?
Padding. Base64 writes three bytes as four characters. If the input length is not a multiple of three, one or two = fill the last group. The decoder on this page also accepts Base64 with the padding left off.
What is URL-safe Base64?
A variant that replaces + with - and / with _, and usually drops the padding, so the result can sit in a URL or file name without escaping. The decoder accepts both alphabets.
Why does decoding say the bytes are not UTF-8 text?
The Base64 is valid, but what it contains is not text. It is probably a file such as an image, a PDF or compressed data. For images, use the Base64 to image tool.
How much bigger does Base64 make my data?
Four characters for every three bytes, so about 33% larger, plus up to two padding characters.

Sources