Files and data
What is Base64?
Also called data URL.
Base64 is an encoding that represents binary data using text characters so it can travel through systems that expect text.
How it works
Many systems were designed to carry text: email bodies, JSON documents, HTML attributes and CSS files. Raw binary data, such as an image, can contain byte values those systems would mangle. Base64 solves that by rewriting every three bytes as four characters drawn from a safe set of 64: A–Z, a–z, 0–9, plus and slash.
A data URL wraps Base64 with a small header that states the file’s MIME type, so a browser knows how to display it: data:image/png;base64,iVBORw0.... This lets you embed an image directly in HTML or CSS instead of linking to a separate file.
The cost is size. The encoded text is roughly one third larger than the original file before transport compression, and it can’t be cached separately from the page it sits in. That makes Base64 a good fit for tiny assets and a poor one for photos.
A practical example
A PNG data URL begins with data:image/png;base64, followed by the encoded image bytes. Pasting that whole string into a browser’s address bar displays the image.
What to watch out for
Base64 isn’t encryption or compression. Anyone with the string can decode the original data, so it doesn’t protect private content, and the encoded text is larger than the file it came from.
Tools you can use
- Image to Base64 · Embed an image directly in your code
Go a little deeper
Common questions
Why is Base64 bigger than the original file?
Every three bytes of binary data become four text characters, so the encoded version is about 33 percent larger. Compression on the web server claws some of that back, but not all of it.
When should I embed an image as Base64?
For very small images such as a tiny icon in an email template or a CSS file, where saving a separate request matters more than the size increase. Large images are better served as normal files.
Is Base64 secure?
No. It is a reversible encoding with no key. Anyone can decode it instantly, so never use it to hide passwords or personal data.