Base64
Base64 is an encoding that represents binary data using 64 safe text characters. It lets you embed a file such as an image or a font directly inside text-based formats like HTML, CSS, JSON, or an email. It is not encryption, since anyone can decode it back to the original bytes.
Why Base64 exists
Some systems only handle text. Email bodies, JSON payloads, and CSS files were not built to carry raw binary. Base64 solves that by translating any file into a long string of safe characters that survives being pasted into those text-only places.
The most common use is the data URI, where a small image is written directly into HTML or CSS so the page does not have to fetch a separate file. It is a convenience, not a security measure, and the size cost means it only makes sense for small assets.
How the encoding works
Base64 reads the data three bytes at a time. Those 24 bits are cut into four groups of six, and each group of six picks one of 64 characters: the capital letters A to Z, the small letters a to z, the digits 0 to 9, and the signs + and /. That is the whole trick, and it is why the output is always four characters for every three bytes in.
When the data does not divide into threes, the last group is padded. One byte left over becomes two characters and two equals signs; two bytes left over become three characters and one equals sign. So the length of Base64 text is four times the number of bytes divided by three, rounded up, and a 30 KB image becomes about 40 KB of text.
The standard that defines it, RFC 4648, also describes a URL-safe variant. It swaps + and / for - and _, because those two signs mean something inside a web address. JSON Web Tokens use this variant and usually leave the padding off. Email is older still: MIME breaks Base64 into lines of at most 76 characters, which is why an encoded attachment arrives as a tall block of text rather than one long line.
When it goes wrong
A string that will not decode is usually one of three things. It may be the URL-safe variant read as the standard one, so - and _ are rejected. Its padding may have been cut off. Or line breaks and spaces from an email were copied along with it. A good decoder tells you which one it found rather than handing back broken bytes.
How to convert an image
- Open the image to Base64 tool.
- Drop in the image you want to inline.
- Copy the encoded string or the ready-made data URI.
The encoding runs in your browser, so the image is never uploaded just to be turned into text.
Frequently asked questions
Is Base64 a form of encryption?
No. Base64 only reformats data into text and can be reversed by anyone. It hides nothing. Use real encryption if you need to protect the contents of a file.
Why is a Base64 image bigger than the original?
Base64 grows the data by roughly a third, because it represents three bytes of binary using four text characters. It trades size for the ability to embed a file inside text without a separate request.
When should I use a Base64 image?
It is handy for tiny icons or single small images you want inlined to save a network request. For larger or reused images, a normal file reference is faster and lighter.