Skip to content
Toolbox

Developers

Base64 Encoding Explained in Plain English

What Base64 is, why it exists, how it turns bytes into text, why it is not encryption, and how to encode or decode a string safely, including URL-safe Base64.

Published · 5 min read

test the image in testing phase

If you have ever looked at a long string of letters and numbers ending in one or two equals signs, you have probably met Base64. It shows up in email attachments, web tokens, configuration files and image links inside web pages. Many people treat it as a mysterious form of scrambling, which leads to a dangerous mistake: believing it protects data. This guide explains what Base64 really does, how it works and when to use it.

What Base64 is for

Computers store everything as bytes, and a byte can have any value from 0 to 255. Many systems that move data around, such as older email protocols or text formats like JSON and XML, were designed to carry plain text only. Some byte values in them have special meanings or are not allowed at all. If you pass a picture or a binary file through such a channel, it can be damaged.

Base64 solves this by rewriting any data using only 64 safe characters: the uppercase letters A to Z, the lowercase letters a to z, the digits 0 to 9, plus the plus sign and the slash. Text made of those characters travels safely through almost any system, and the receiver turns it back into the original bytes.

How it works

Base64 reads the data three bytes at a time. Three bytes are 24 bits, and 24 divides neatly into four groups of six bits. Each six-bit group has a value from 0 to 63, which is used as a position in the 64-character alphabet. So every three bytes of input become four characters of output.

A famous small example is the word Man. Its three bytes become the four characters TWFu. When the input length is not a multiple of three, the last group is filled up and the output is padded with one or two equals signs. That is why the word Hello, which has five bytes, becomes SGVsbG8= and why Hello, World! becomes SGVsbG8sIFdvcmxkIQ==.

Because four characters carry only three bytes of data, Base64 makes data about one third larger. That is the price of safe transport.

Base64 is not encryption

This is the most important point. Base64 is just a different way of writing the same information, and anyone can reverse it in a second without any key or password. If you see a Base64 string, assume that its content is readable.

Web tokens are a common example. The two readable parts of a JSON Web Token are Base64 versions of JSON, so anyone holding the token can decode and read what is inside. Never put passwords or private details into something simply because it will be Base64 encoded. If data must stay secret, it needs real encryption.

Text, emoji and other languages

Base64 works on bytes, not on letters, so text must first be turned into bytes. The standard way is UTF-8, which handles every language and emoji. Problems appear when a tool encodes text using a limited character set. The classic browser function btoa, for example, fails on characters outside a small range. Our Base64 Encoder and Decoder converts text with UTF-8 first, so accents, emoji and alphabets such as Arabic or Chinese come back unchanged when you decode them.

The URL-safe variant

The plus and slash characters have special meanings inside web addresses and file names. A variant described in the standard that defines Base64 replaces them with a dash and an underscore, and often leaves out the padding. This is usually called Base64URL, and it is what web tokens use. In the tool you can switch on the URL-safe option when you need text that can sit in a link without trouble.

Step by step with the tool

  1. Open the Base64 Encoder and Decoder.
  2. Choose Encode to turn text into Base64, or Decode to go the other way.
  3. Paste your input. When decoding, the tool checks the characters and explains what is wrong if the text is not valid Base64.
  4. Copy the result. The Use result as input button helps when you want to check a round trip, or when a value was encoded twice.

Everything happens in your browser, so the text you enter is not uploaded.

When Base64 is a good idea

  • Embedding a small image directly in a web page or stylesheet as a data address.
  • Sending binary content inside JSON or XML.
  • Putting small pieces of data in a link or a header.
  • Reading what a token or an encoded setting contains while you debug.

It is a poor choice for large files, because of the size increase, and it should never be used as a way to hide information.

Common errors and what they mean

Invalid characters. A stray space, a line break added during copying or a character from another alphabet will break decoding. Remove them and try again. Dashes and underscores are not a problem, because the decoder reads the URL-safe form as well as the standard one.

Missing padding. Some systems drop the equals signs. A good decoder, including ours, accepts that, but others may complain.

Not readable text. If the original data was not text, for example an image, a compressed file or an encrypted value, there is no readable text to show. The tool tells you so. Base64 decoded the bytes correctly, but what is inside is binary.

Double encoding. A string that decodes to another Base64 string was encoded twice. Decode it a second time.

When your decoded data turns out to be JSON, the JSON Formatter will lay it out so it is easy to read. Between the two tools, you can inspect most encoded values you run into without installing anything.

Try it yourself

Free, private and it runs in your browser.

More guides