Sooner or later you will meet a wall of text that starts with data:image/png;base64, and runs on for thousands of characters. It looks like a bug, or like a file that exploded. It is neither. It is an image, written out as text so that it can live inside a web page, a stylesheet or a JSON document instead of sitting in a file of its own.
That wall of text is called a data URL, and the writing system is base64. This explainer takes the idea apart slowly: what base64 does to an image, the four parts every data URL is built from, and how to verify the whole thing yourself with the free Base64 Image Encoder and Decoder on Ovatly.
Contents
- Quick answer
- An image, written as text
- The anatomy of a data URL
- Worked example: checking QUJD for yourself
- Why the text form is a third larger
- Where a data URL can go
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
A base64 image is a normal image whose bytes have been rewritten as text using the base64 alphabet, then wrapped in a data URL: a prefix like data:image/jpeg;base64, followed by the encoded payload. The picture has not changed; only its written form has. Browsers can read the text and render the image directly, which is why data URLs get pasted into an img src or a CSS background. The trade is size: base64 expands data by a factor of 4/3, so the text is always about one third larger than the file it came from.
An image, written as text
An image file is binary data: a long sequence of bytes that text editors, email systems and many web formats handle badly or not at all. Base64 solves a transport problem. It rewrites those bytes using a safe alphabet of letters, digits and a couple of symbols, characters that survive any text system untouched. Nothing about the image is compressed, converted or improved in the process. The same bytes go in one end, get written in a different alphabet, and can be rebuilt exactly at the other end.
That is why the Base64 Image Encoder and Decoder works in both directions. Encoding turns an image into a data URL you can paste into HTML, CSS or JSON. Decoding takes such a data URL and turns it back into a downloadable image file. One idea, read forwards and backwards.
The anatomy of a data URL
Every image data URL has the same four parts, in the same order. Reading them once makes every example afterwards easy to scan.
- The scheme:
data:The string starts withdata:instead of thehttps:you see in a normal web address. It is a promise that the content is not somewhere else on the internet; it is right here, in this string. - The image type: for example
image/jpegNext comes the type of the embedded data, such asimage/jpegorimage/png. This tells the browser how to interpret the bytes once they are decoded. - The marker:
;base64This short marker announces that the payload is base64 text, rather than some other kind of inline data. - The payload After the comma, the rest of the string is the image itself in base64 characters. This is the long part, and it is the part that must arrive complete and unchanged.
Put together, a short one looks like this:
data:image/jpeg;base64,QUJD...
The decoder in the tool checks exactly this shape. A string that is missing the data: prefix, names a non-image type, or contains characters outside the base64 alphabet is rejected with an explanation of which part to check.
Worked example: checking QUJD for yourself
The encoder entry gives a verification small enough to do by hand. The payload QUJD is exactly 3 bytes: the letters ABC. Base64 groups data in threes, so those 3 bytes become the 4 characters QUJD, and decoding them returns the same 3 bytes, the same three letters.
You can confirm the direction of travel with the tool itself. It computes the decoded byte length from the payload, so the number it reports is derived from the text you gave it, not from a stored file. Paste a data URL into the Base64 Image Encoder and Decoder, switch to decoding, and click Decode to image: the preview that appears was rebuilt byte by byte on your device from nothing but text. That is the whole concept in one click.
Why the text form is a third larger
The 4/3 ratio follows directly from the grouping. Every 3 bytes of image become 4 characters of text, so the encoded form is always about one third larger than the file, before the short prefix is added. The entry's example makes it concrete: a 30,000 byte JPEG becomes about 40,000 base64 characters, plus a prefix like data:image/jpeg;base64,.
There is no quality setting or clever option that shrinks this. Base64 is a writing system, not a compressor. If the encoded size bothers you, the answer is to shrink the image itself first, with a resize or a compression pass, or to keep the image as a file and link to it in the ordinary way.
Where a data URL can go
A data URL can be pasted in an img src, in a CSS background, or anywhere a URL is accepted. The browser reads the embedded bytes directly at render time, with no separate file to host and no extra request to make. Developers reach for this for tiny inline icons and for email-safe assets, the two jobs the encoder entry names: places where a small image needs to travel inside the document rather than beside it.
The same property that makes this convenient also sets its limit. Because the image is part of the page text, the encoded text cannot be cached separately, so it is downloaded again wherever it appears. A linked file is fetched once and reused; a data URL is paid for on every page, every time.
Limitations and honest tradeoffs
Data URLs are convenient for very small images, and the convenience fades fast as size grows. Anything beyond a few kilobytes usually belongs in a real file: the text is a third larger, it cannot be cached separately, and a page carrying several embedded images becomes heavy and hard to maintain.
The text is also fragile in a way files are not. A data URL decoded on your device is rebuilt byte by byte, so a single missing character in the paste changes or breaks the result. And the decoder is deliberately narrow: only base64 data URLs for images are decoded. Plain base64 without the data: prefix, and non-image types, are rejected with an explanation rather than guessed at.
Common mistakes
- Assuming base64 is a separate image format. It is a way of writing an image as text. The JPEG or PNG inside is unchanged.
- Pasting plain base64 into the decoder. Without the full data URL shape, starting with
data:and naming an image type, the text is rejected. - Losing characters when copying. A shortened paste does not produce a slightly wrong image; it produces a broken one. Copy the string whole.
- Embedding large images to save a request. The swap trades one cached file for a third more text on every page load. It loses quickly as images grow.
- Trying to edit the payload. The characters are the image. Changing any of them changes the picture, almost always for the worse.
FAQs
Why is the data URL so much longer than the file? Base64 encodes 3 bytes into 4 characters, so text form is always about one third larger, before the data:image prefix. That overhead is the price of embedding binary data in text.
Where can I paste a data URL? In an img src, a CSS background, or anywhere a URL is accepted. Browsers read the embedded bytes directly, with no separate file to host.
The decoder rejected my text. Why? The decoder checks the full shape: it must start with data:, name an image type, include ;base64, and contain only valid base64 characters. The error message tells you which shape to check.
Is anything uploaded when I use the encoder or decoder? No. Reading and decoding happen entirely in your browser, on your own device.
Is a base64 image a different kind of image? No. It is the same image, byte for byte, written in a text alphabet. Decoding rebuilds the original file from the text, which is why a single missing character changes or breaks the result.
Conclusion
A base64 image is an ordinary image wearing a text costume: same bytes, safer alphabet, wrapped in a data URL whose four parts you can now read at a glance. Keep the size rule in mind, a third larger and never cached separately, and the technique stays a tidy solution for tiny icons and self-contained documents. When you are ready to do it rather than read about it, our walkthrough of how to embed an image in HTML using base64 takes you through the steps. For more guides in this series, see our Image Tools guides, which pair each technique with the free tool that performs it.
References
- MDN Web Docs, on data URLs and how browsers handle them: https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data
- RFC 2397, the "data" URL scheme specification: https://www.rfc-editor.org/rfc/rfc2397
- RFC 4648, on the base64 encoding itself: https://www.rfc-editor.org/rfc/rfc4648