You have seen markup like `<img src="data:image/png;base64,iVBORw0...">`. Instead of pointing at an image file, the file's contents have been turned into text and pasted into the document. It looks convenient, and used carelessly it makes pages slower.
What you are trading
Base64 represents every three bytes of binary as four characters, so the result is **about 33% larger** than the original. What you buy with that is exactly one thing: the file no longer has to be fetched separately. Whether the trade pays off depends on how big the image is and how often it appears.
| As a separate file | Inlined as Base64 | |
|---|---|---|
| Bytes transferred | Original size | About 1.33x |
| Requests | One per image | None — it is part of the document |
| Browser cache | Reused per image | Not possible — re-sent with the document |
| Document size | Unchanged | Grows by the size of the image |
| Replacing it | Swap the file | Edit and redeploy the document |
Losing the cache is the expensive part
The row that actually hurts is caching. As a file, the browser fetches the image once and reuses it on the next page. Embedded as text, the blob comes down again with every page. Inline your logo and ship twenty pages, and a visitor downloads the same logo twenty times.
Inlining into CSS is subtler. CSS files usually cache well, so the image caches with them — but **nothing renders until the CSS has finished downloading.** Bury a heavy image in your stylesheet and you have delayed first paint.
When it pays off
- **Icons of a few kilobytes** — saving a request beats the 33% overhead.
- **Places that cannot reference external files** — email signatures, single-file HTML documents, offline reports.
- **Somewhere a flash of missing content would show** — tiny background patterns that appear late are noticeable.
- **When adding a file to the build is awkward** — a one-line stopgap asset.
When it costs you
- **Photographs** — hundreds of kilobytes grow by a third and cannot be cached. A file is nearly always better.
- **Anything repeated across pages** — logos and header art are precisely what caching is for.
- **Images that change often** — every change means editing and redeploying the document.
- **A whole set of icons** — inline SVG or a sprite serves you better.
For small icons, look at SVG first
For simple iconography, inlining the SVG source is usually shorter than Base64-ing a PNG. SVG is already a text format, so there is no 33% penalty, its colour can be driven from CSS, and it stays sharp at any resolution. Base64 earns its place when the artwork cannot be expressed as SVG.
Conversion happens inside your browser, so the image is never uploaded. The reverse direction works in the same place: paste a data URI string back and get the image file, which is handy when you need to see what a blob buried in a log or an API response actually is.