Skip to main content
C
CodeUtil

Image to Base64: When Embedding Makes Sense (And When It Doesn't)

At Šikulovi s.r.o., we base64-encoded every icon on a client's landing page. Page load time doubled. Here's what that disaster taught me about when embedding actually makes sense.

2025-11-277 min
Related toolImage to Base64 Converter

Use the tool alongside this guide for hands-on practice.

The day I broke page load time with base64 images

Back in 2019, I was optimizing a landing page and read somewhere that inline images eliminate HTTP requests. Brilliant, I thought. So I converted every icon, logo, and decorative image to base64. The result? My HTML file went from 50KB to 400KB, and the page actually loaded slower than before.

That was the day I learned that base64 encoding increases file size by roughly 33%. A 10KB image becomes about 13.3KB when base64-encoded. And since it is embedded in HTML or CSS, it cannot be cached separately. Every page load re-downloads those images as part of the document.

When base64 images actually help

Despite my disaster, there are legitimate cases where base64 embedding makes sense. The key is understanding the trade-off: you eliminate one HTTP request but increase the file size and lose caching benefits.

  • Tiny images under 2KB where the HTTP request overhead exceeds the size penalty
  • Critical above-the-fold icons that must render immediately without waiting for additional requests
  • Email templates where external images are often blocked by email clients
  • Single-page applications where you want zero external dependencies for offline capability
  • Favicons embedded in HTML for instant display without a separate request
  • CSS background images that are essential for the initial render

The math behind the 33% overhead

Base64 encoding converts binary data to ASCII characters. Every 3 bytes of binary becomes 4 characters of base64. That is where the 33% comes from. But it gets worse with gzip compression.

Binary images like PNG and JPEG are already compressed. When you base64-encode them, the resulting text compresses poorly compared to the original binary. A 10KB PNG might gzip to 9KB. The same image base64-encoded might only gzip to 12KB. You lose twice.

CSS sprites vs base64: the old debate

I remember when CSS sprites were the gold standard for icon optimization. You combined all icons into one image and used background-position to show each one. It felt hacky but it worked.

Today, I rarely use either technique. SVG icons with proper caching beat both approaches. But if you are stuck with raster icons, here is my rule: use sprites if you have more than 5 icons of similar size, use base64 if you have 1-3 tiny critical icons, and use individual files with HTTP/2 for everything else.

  • CSS sprites: One request for many icons, but complex to maintain and update
  • Base64: Zero requests but larger files and no caching
  • Individual files with HTTP/2: Multiple requests are cheap now, and each file caches independently
  • SVG sprites: Best of all worlds for vector icons

Base64 in email templates: the exception

Email is the one place where I still use base64 liberally. Most email clients block external images by default. When a user opens your email, they see broken image placeholders until they click "display images."

Base64 images embedded directly in the email body often render without that extra click. The trade-off is larger email size, but for critical images like your logo, it is usually worth it. Just keep it to a few small images - embedding large photos will get your emails flagged as spam.

My current workflow for image optimization

After years of experimenting, here is what I do now. First, I optimize the image itself - compress it, resize it, choose the right format. Then I ask: is this image critical for the initial render? Is it under 2KB? Will it be used in email?

If yes to any of those, I consider base64. Otherwise, I serve it as a regular file and let the browser cache it. Modern HTTP/2 makes multiple small requests nearly free, so the old "reduce HTTP requests" advice is less relevant than it used to be.

  • Start with proper image optimization before considering embedding
  • Use WebP or AVIF formats when browser support allows
  • Keep base64 for truly critical, tiny, or email-specific images
  • Measure actual performance, do not just count requests
  • Consider lazy loading for below-the-fold images instead of embedding

Using the Image to Base64 converter

When you do need to convert an image to base64, the process is simple. Drop your image into the converter, and you get the base64 string plus the complete data URI ready to paste into your code.

I added a file size comparison feature because I kept forgetting to check the original size. Now I can see immediately if the base64 version is worth it. If your 50KB hero image is becoming 67KB of base64 text, that is a sign to use a regular image tag instead.

FAQ

What's the maximum image size for base64?

I stick to under 10KB, but honestly, under 2KB is the sweet spot. Beyond that, the 33% overhead and loss of caching usually hurt more than the saved request helps.

Does base64 work in all browsers?

Yes, data URIs work in all modern browsers and have for years. IE8 had a 32KB limit, but that is ancient history now. The only place I see issues is some email clients with very aggressive image blocking.

Should I base64-encode SVGs?

Usually no. SVGs are already text, so you can inline them directly in HTML without base64 encoding. If you need them in CSS background-image, you can URL-encode the SVG instead of base64 - it's smaller.

How do I convert multiple images at once?

For batch conversion, I use a build tool like webpack or a Node script. The browser-based converter is great for one-off conversions, but for a whole project, you want automation.

Does base64 affect SEO?

Search engines can't see base64-embedded images as easily as regular img tags with src attributes. For decorative images, that's fine. For content images you want indexed, use regular image tags with descriptive alt text.

Martin Šikula

Founder of CodeUtil. Web developer building tools I actually use. When I'm not coding, I experiment with productivity techniques (with mixed success).

Related articles

12 min

Code Minification: Best Practices for Production

After years of optimizing builds at Šikulovi s.r.o., I have developed a battle-tested approach to minification. Here is my complete guide to build tool integration, source maps, and avoiding common pitfalls.

Minifierminificationperformanceweb development