Guides / Files and data guides

Base64 Encoding Explained: What It Is and When to Use It

Written by the convertalldoc team. Updated

Base64 is a way of writing any data, such as an image, a PDF or a piece of text, using only letters, digits, plus, slash and sometimes an equals sign. That makes it safe to place inside formats that can only carry plain text. To encode or decode something right now, open Base64 Encode and Decode, paste your text or choose a file, pick encode or decode, and copy the result. It all happens in your browser.

How to encode or decode with the tool

  1. Open Base64 Encode and Decode.
  2. Choose Encode or Decode.
  3. Type or paste your text. To encode a file, choose it in the box below the text area. Files up to 25 MB are supported.
  4. Turn on any options you need: URL-safe, line wrapping at 76 characters, or a data: URI prefix (for files only).
  5. Copy the result, or download it.

Text is converted to UTF-8 before encoding, so accents, other alphabets and emoji survive the round trip. When decoding, the tool accepts standard and URL-safe Base64, with or without the equals padding, and it ignores spaces and line breaks in what you paste.

When the decoded result is not text

If you decode something that was originally a picture or a PDF, the bytes are not readable text. The tool tells you so, and you can download the result as a file instead of reading it on screen. If you know it is an image, the quickest route is Base64 to Image, which previews the picture and names the download to match its real type.

Why Base64 exists

Many systems were designed to carry text and nothing else. Email bodies, JSON, XML, HTML, CSS and some web address fields can be corrupted if you push raw bytes through them, because certain byte values are treated as control characters or line endings. Base64 translates bytes into a small, safe alphabet of 64 characters so the data passes through unharmed, and then the receiver converts it back.

You meet it more often than you might think:

How it works, in plain terms

Base64 takes your data three bytes at a time. Three bytes are 24 bits, and those 24 bits are split into four groups of six bits. Each group of six bits is a number from 0 to 63, and each number maps to one character: the capital letters, then the lower-case letters, then the digits, then plus and slash. So three bytes become four characters.

If the data does not divide neatly into threes, the end is filled out with one or two equals signs. These are called padding. You will often see a Base64 string ending in = or ==. That is not part of your data; it just tells the decoder how many bytes the last group held.

A short example: the word Man becomes TWFu. The text Hello becomes SGVsbG8=, and the equals sign is padding because five bytes do not divide by three.

It is not encryption

Base64 only changes how data is written. It has no key and no secret, and anyone can decode it in seconds, including with the tool on this page. Never use it to hide passwords, tokens or private information. If you see a value that looks like random letters and ends with an equals sign, do not assume it is protected. Treat a Base64 string exactly as you would the original data.

The size cost

Because three bytes become four characters, Base64 output is about one third larger than the original, or roughly 33 percent. A 300 KB image becomes about 400 KB of text. If you turn on line wrapping, the line breaks add a little more.

That overhead explains the usual advice. Embedding a tiny icon in your code is fine and saves a network request. Embedding a large photo makes your page heavier and the browser cannot cache the image on its own. To check how big a string will be, use the File Size Converter, and if the original is too large, shrink it first with the image compression guide.

Standard and URL-safe Base64

Standard Base64 uses plus and slash. Both of those have special meaning in web addresses and file paths, so a second form exists: URL-safe Base64 replaces plus with a minus sign and slash with an underscore, and usually leaves out the equals padding. It is common in tokens and in links.

In the tool, tick URL-safe when you want that variant on output. For decoding you do not need to choose, because both forms are accepted automatically. If a decoded result looks wrong, check which variant you have, and whether anything was cut off when you copied it. For more on special characters in addresses, see URL encoding explained. The two are different things: Base64 turns binary into text, while URL encoding makes text safe inside a link.

Images as Base64 and data URLs

A data URL puts an entire file inside a piece of text, with a prefix that tells the browser what it is, such as data:image/png;base64, followed by the encoded content. You can paste it where a normal image address would go, in an img tag or a CSS url().

Use this for tiny images such as small icons and logos. For anything bigger, a normal image file is better, because it can be cached and does not bloat your page.

Practical scenarios

Inspecting a value from an API response

You have a field full of letters and digits and you want to know what it holds. Paste it into the tool and choose Decode. If the result is readable text, such as JSON, you can read it. If it says the data is not text, download it and check the file type.

Embedding a small logo in an HTML email or page

Convert the logo with Image to Base64, copy the data URI and paste it into the src attribute. Keep the image small, and test it, because support for data URLs differs between email programs.

Sending a short text through a system that mangles characters

Encode it, send the encoded form, and decode it at the other end. Because the tool uses UTF-8, accents and emoji arrive intact.

Saving a file as text

Choose the file, copy or download the Base64 result, and later decode it back to the same file. Check the file after decoding, since a single missing character means the result will not open.

Troubleshooting

Common mistakes

Related tools and guides

If you are working with files, the ZIP guide shows how to bundle several files into one, which you can then encode as a single item. Base64 and ZIP solve different problems: ZIP groups and compresses, Base64 only changes the writing system.

Should you use Base64 at all?

It helps to ask what problem you are solving before reaching for it.

A useful habit is to decode any unfamiliar Base64 you are sent before you trust it, and to remember that the sender can put anything in it, including content you did not expect. Decoding in your browser lets you look at it without sending it anywhere.

Privacy

Encoding and decoding happen in your browser. Your text and files are not sent to a server.

Frequently asked questions

Is my data uploaded when I use the Base64 tool?

No. Encoding and decoding happen in your browser and nothing is sent to a server.

Does it handle accents, emoji and other languages?

Yes. Text is converted to UTF-8 bytes before encoding and decoded the same way, so non-English text round-trips correctly.

What is URL-safe Base64?

A variant that uses minus and underscore instead of plus and slash, and usually leaves out the equals padding. Decoding accepts both kinds automatically.

Can I encode a file, such as an image?

Yes. Choose the file and the Base64 text appears. You can add a data: URI prefix to use it directly in HTML or CSS. Files up to 25 MB are supported.

Why is Base64 bigger than the original?

Base64 stores three bytes as four characters, so the text is about 33 percent larger than the original data.

Why does decoding show an error?

The text contains characters Base64 does not use, or its length is not valid, which often means it was cut off when copied. Spaces and line breaks are ignored.

Is Base64 a way to protect data?

No. It only changes the format. Anyone can decode it, so do not use it to hide secrets.

More guides

All guides