← Back to home
Home › Image Guides › Base64 images

Base64 Images: When to Use Data URLs (and When Not To)

Base64 turns an image into plain text you can paste straight into HTML or CSS. It removes one network request, but it also makes the file about a third bigger. This guide covers what is actually happening, when a data URL genuinely helps, and when it quietly hurts your page.

What a base64 image actually is

A base64 image is not a new image format. The picture is still a PNG, JPG or WebP — base64 is only a way of writing its bytes using 64 safe text characters, so they can live inside a file that is otherwise plain text.

Written out in full it is called a data URL, and it always follows the same shape:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...

Three parts, separated by punctuation:

  • data: — tells the browser this is inline content, not an address to fetch.
  • image/png;base64 — the MIME type, then the encoding used.
  • iVBORw0... — the encoded bytes themselves, which is the long tail of the string.

Because it is just text, you can drop it into an <img src>, a CSS background-image, or a JSON response. The browser decodes it back into a picture on the fly, with no separate file involved.

Why the file gets about 33% bigger

Base64 encodes every 3 bytes of binary data into 4 text characters. Three bytes is 24 bits, and each base64 character carries 6 bits, so 24 bits needs exactly 4 characters. That gives a fixed overhead:

  • Encoded size ≈ original size × 1.333
  • A 30 KB icon becomes roughly 40 KB of text
  • A 1 MB photo becomes roughly 1.33 MB of text

That overhead never shrinks, no matter which image format you start from. It is the price of representing binary data using only printable characters.

When a data URL genuinely helps

  • Tiny icons and UI graphics — a 1 KB icon pasted inline saves a round trip that costs more in latency than the image itself.
  • Single-file deliverables — an HTML email, a self-contained demo page, or a document that must work offline with no accompanying assets folder.
  • Guaranteeing a critical graphic paints immediately — inlining a small above-the-fold element means it cannot be delayed by a failed request.
  • APIs and configs that only accept strings — some build tools and JSON payloads cannot reference a separate file.

A widely used rule of thumb: inline only if the encoded result stays under roughly 2 KB. Beyond that, the size penalty starts costing more than the request you saved.

When you should not use one

  • Large images — the 33% overhead scales linearly. Inlining a 500 KB photo adds about 165 KB for no benefit.
  • Anything that needs independent caching — an external image file can be cached on its own. Inlined, it is re-downloaded every time the host document changes.
  • Images you want found in image search — search engines index image files at their own address. A data URL has no address to index.
  • Content-heavy pages — a wall of base64 text bloats the HTML and slows down parsing on weak connections.

One more consideration: under HTTP/2 and HTTP/3 many small requests are multiplexed cheaply, so the old "one request saved" argument is much weaker than it used to be.

How to convert an image to base64

The Base64 Converter does both directions and runs entirely in your browser, so the file never leaves your device. Upload an image to get the data URL, or paste a string back in to decode it and download the original picture.

If you need it in code instead, every common runtime has a built-in way:

  • JavaScript — FileReader.readAsDataURL() for files, btoa() for strings
  • Python — base64.b64encode(open('a.png','rb').read())
  • Command line — base64 -i image.png

FAQ about base64 images

Is a base64 image a different format from PNG or JPG?
No. The image data is unchanged — base64 is only an encoding used to represent those bytes as text. A base64 PNG is still a PNG the moment it is decoded.
Does it work with every image format?
Yes. Anything with a MIME type can be inlined, including WebP, SVG and GIF. SVG is a special case worth noting: because it is already text, you can often inline it directly instead of base64-encoding it, which avoids the 33% penalty entirely.
Can I paste a string without the data: prefix?
Yes. Most tools including this one add the data:image/png;base64, prefix automatically before parsing. If the original is a JPG but the prefix says PNG, most browsers still identify the real type correctly.
Why does my base64 string fail to load?
Almost always line breaks. Paste a single continuous string — if the encoding was wrapped for readability, remove the newlines first. A missing or malformed prefix is the second most common cause.
Is there a size limit?
Encoding is limited by browser memory, usually fine up to tens of megabytes. But a 1 MB image becomes 1.33 MB of text, which is impractical to inline — this technique is meant for assets of a few KB.
Does base64 help SEO?
Indirectly at best. It removes a request but makes the page heavier, and inlined images cannot be indexed in image search. For anything larger than a small icon, a normal file URL with proper alt text is the better choice.