Guides / Files and data guides
Base64 Encoding Explained: What It Is and When to Use It
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
- Open Base64 Encode and Decode.
- Choose Encode or Decode.
- 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.
- Turn on any options you need: URL-safe, line wrapping at 76 characters, or a data: URI prefix (for files only).
- 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:
- Email attachments are traditionally carried as Base64 text inside the message.
- Small images placed directly inside HTML or CSS as data URLs.
- Values in JSON APIs that need to hold a file or a block of binary data.
- Parts of tokens and configuration values that must be a single line of plain text.
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().
- To make one from a picture, use Image to Base64. It gives you both the raw string and the full data URI.
- To turn a string back into a picture, use Base64 to Image. You can paste either the plain string or the whole data URI.
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
- An error about a character. Base64 uses only letters, digits, plus, slash, minus, underscore and equals. A quote mark, bracket or comma usually means extra text was copied along with the string.
- An error about length. The string was probably cut off. Copy it again in full.
- Accents look garbled. The data was probably not UTF-8 text in the first place, or it was encoded elsewhere using a different character set.
- The decoded file will not open. Confirm that you are using the correct file extension and that nothing was truncated.
- It decodes but is not an image. The string may be a different kind of file, or the Base64 of ordinary text.
Common mistakes
- Treating Base64 as security. It is only a format.
- Mixing up Base64 with URL encoding. Percent codes such as %20 are a different system.
- Embedding large images, which makes pages slow.
- Copying a data URI without its prefix, or the prefix without the data.
- Forgetting that line breaks or extra spaces inside a string can break decoding in some other systems, even though this tool ignores them.
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.
- You must put binary data into a text-only field: Base64 is the standard answer.
- You want to make a file smaller: Base64 does the opposite. Compress the file itself instead.
- You want to hide something: Base64 does not hide anything. Use proper encryption, and keep secrets out of places where they can be copied.
- You want a small image to load with the page: a data URL can work for a tiny icon, but a normal file is usually better for anything larger than that.
- You want a safe value inside a web address: consider whether percent encoding is the better fit, or use the URL-safe variant of Base64.
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.