What Is a Base64 Image and When Should You Inline One?

Quick answer

How Base64 turns an image into text, why you would embed one directly in code, and when it helps versus when it hurts performance.

By · Published 2026-07-31 · Updated 2026-10-03 · 1153 words · about 5 minute read

An image dissolving into a stream of encoded characters embedded in code

A Base64 image is a picture that has been converted into a long string of plain text, so it can be embedded directly inside HTML, CSS or JSON instead of living in a separate file. That text string is called a data URI, and it starts with something like data:image/png;base64, followed by thousands of characters. The Image to Base64 tool produces one from any image in your browser. This article explains how it works and, more importantly, when inlining an image is a good idea and when it is a mistake.

Base64 encoding is genuinely useful in the right situation and genuinely harmful in the wrong one, so understanding the trade-off is what separates a clever optimisation from a self-inflicted performance problem.

How Base64 turns an image into text

Computers store images as binary data, raw bytes, which cannot always travel safely through systems designed for text, such as HTML source or JSON. Base64 is an encoding that maps binary data onto a set of 64 safe, printable characters (A-Z, a-z, 0-9, plus two symbols). Every three bytes of image become four text characters. The result is completely reversible: the same image comes back byte-for-byte when decoded. The cost is size, Base64 text is about 33% larger than the original binary, because it trades three bytes for four characters.

An image file transforming into a long string of encoded text
Base64 turns an image's bytes into text that can live directly inside code.

What a data URI looks like

When you inline an image, you wrap the Base64 text in a data URI so the browser knows what it is. The format has three parts: the media type (image/png), the encoding marker (base64), and the encoded data itself. You can drop that whole string anywhere a URL is expected, the src of an img tag, a CSS background-image, or a JSON field, and the browser renders it as though it had downloaded a file, except no separate download happens.

The 33% size penalty is real

Because Base64 inflates data by a third, a 30 KB image becomes about 40 KB of text. Inlining trades a separate network request for a larger main file. That trade is worth it for tiny images and terrible for large ones.

When inlining an image helps

Base64 inlining shines for small, frequently used images where avoiding a separate network request matters more than the size penalty:

  • Tiny icons and logos embedded in CSS, so they load with the stylesheet and never cause a flash of missing image.
  • Single-file deliverables: an HTML email or a self-contained page that must work without any external files.
  • Small images in JSON APIs, where sending the image inline avoids a second round trip.
  • Placeholder or fallback graphics that need to be guaranteed available even offline.

When inlining an image hurts

For anything but small images, inlining is usually a mistake. Large Base64 strings bloat your HTML or CSS, which the browser must download and parse before it can render the page, so a big inlined image delays everything. Inlined images also cannot be cached separately, a linked image file is downloaded once and reused across pages, but an inlined one is re-sent with every page that contains it. As a rule of thumb, inline only images below a few kilobytes, and link everything larger as a normal file.

An HTML block with an image embedded inline rather than linked
A data URI puts the whole image into the page, so there is no separate file to fetch.

Compress first, then encode

Because Base64 adds a third to the size, it pays to make the image as small as possible before encoding. Run it through an image compressor first, and for icons consider whether an SVG (which is already text and needs no Base64) would be smaller still. Only encode the minimal, compressed version.

Try it: Image to Base64

Convert any image to a Base64 data URI ready to paste into HTML, CSS or JSON, entirely in your browser. Your image never leaves your device.

Encoding, decoding and privacy

The process is fully reversible: a Base64 encoder/decoder can turn the text back into the original image, which is worth remembering, Base64 is an encoding, not encryption, and offers no privacy on its own. Anyone with the string can reconstruct the picture. Because encoding happens entirely in your browser here, the image you convert is never uploaded, so even a sensitive graphic stays on your device while you generate its data URI.

How browsers treat inlined versus linked images

Understanding how a browser handles the two approaches makes the trade-off concrete. When an image is a linked file, the browser first downloads the HTML, discovers the image reference, and then makes a separate request for the file, which it can cache and reuse on every future page. When an image is inlined as Base64, there is no separate request at all: the image data arrives baked into the HTML or CSS. That removes a round trip, which is genuinely valuable for a handful of tiny, critical images that you want painted the instant the page loads.

A comparison of an external image link versus inline embedded data
Inline base64 saves a request but makes the file bigger; large images are better linked.

The catch is caching and parsing. A linked image is downloaded once and reused across every page that references it, so a shared logo costs one download for the whole site. An inlined image is re-embedded in every page or stylesheet that uses it, so the same logo is re-sent again and again, and the browser must parse that large text blob as part of the document before it can render. For one small icon the maths favours inlining; for a large image, or one used across many pages, linking wins comfortably. The rule of thumb, inline only a few kilobytes, link everything bigger, falls straight out of this behaviour.

A final practical note: because a Base64 string is just text, you can store it, email it, or paste it into a document like any other text, and it will always reconstruct the exact same image. That portability is part of the appeal for single-file deliverables. But it also means a data URI is as long as the image is large, so a page full of inlined images becomes genuinely unwieldy to read and edit in source form. Reserve inlining for the few small graphics where the benefit is real, and your code stays readable.

The bottom line: Base64 images let you embed pictures directly in code as text, which is perfect for tiny, always-needed graphics and poor for large ones. Keep inlined images small, compress before encoding, and link anything substantial as a normal cached file. Used with that judgement, data URIs are a neat tool; used indiscriminately, they quietly slow pages down.

Frequently asked questions

What is a base64 image data URI?

It is an image encoded as text and embedded directly in a web page or stylesheet using a data: URL. Instead of linking to a separate image file, the whole image travels inside the HTML or CSS as a base64 string the browser decodes.

Why would I embed an image as base64?

To avoid a separate network request, which can speed up tiny, frequently used images like icons, and to keep an image self-contained in a single file or email. It removes the need to host or link the image elsewhere.

What are the downsides of base64 images?

Base64 makes the data about a third larger than the original file, it cannot be cached separately by the browser, and large embedded images bloat your HTML or CSS. For big images, a normal linked file is usually faster.

When should I use a data URI versus a normal image file?

Use base64 for very small, reused assets such as icons and simple backgrounds, or when you need everything in one file. Use a normal linked image for photos and anything large, so the browser can cache it and load the page faster.

How do I convert an image to base64?

Upload or drop the image into our base64 tool and it outputs the data URI ready to paste into your HTML or CSS. It runs in your browser, so the image is never sent to a server.

Tools mentioned in this article

Continue reading

← More articles · Browse all 117 tools

Pick a theme

Ten hand-tuned palettes.