Image to Base64

Choose, drop or paste an image and get it as a data URL, ready-made snippets for HTML, CSS and Markdown, and the size it will add to your page. The image is read on this device and never uploaded.

How it works

A data URL puts a whole file inside a link: data:, the file’s type, ;base64, and then the file’s bytes written in Base64. A browser treats it like any other image address, so it can go in an img tag, a CSS background or a Markdown file without a separate download.

The image type is read from the first bytes of the file, not from its name. A PNG always starts with the same eight bytes, a JPEG with FF D8 FF, and so on. That way a photo saved as .png by mistake still gets the right type, and a file that is not an image is caught before it is encoded.

Base64 writes every 3 bytes as 4 characters, so the text is about a third bigger than the file. The page shows both sizes and warns you when the result is large enough that inlining it is likely to slow your page down rather than speed it up.

How to use it

  1. 1 Choose an image, or drop or paste one onto the page.
  2. 2 Check the type that was detected and the two sizes: the original file and the encoded text.
  3. 3 Pick the form you need: Data URL, Base64 only, HTML <img>, CSS background or Markdown.
  4. 4 Press Copy next to it and paste it into your code.

Good to know

  • Inline only small images: icons, tiny logos and placeholders of a few kilobytes. Larger images are better as normal files the browser can cache.
  • An image inlined in CSS or HTML is downloaded again with every copy of that file, and it blocks the file from being cached separately.
  • For SVG, a URL-encoded data URL (data:image/svg+xml, followed by the escaped markup) is often smaller than Base64, because SVG is already text.
  • Email clients handle data URLs badly. Many strip them, so use them in web pages rather than in HTML email.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

The smallest PNG there is, as a data URL

A good way to understand data URLs is to take a tiny image and follow it all the way into a page. Our example is a PNG one pixel wide and one pixel high. It is a complete, valid image file, and it is 70 bytes long. That is small enough to read every part of it, and it is also exactly the kind of image that is worth inlining.

First, what kind of file is it? The name could say anything, so the tool looks at the first bytes instead. Every PNG in the world begins with the same eight: 89 50 4E 47 0D 0A 1A 0A in hex. The middle three spell PNG in ASCII. The rest were chosen to catch files damaged in transfer: a line ending that some systems rewrite, and a byte that stops old terminals from printing the file. If those eight bytes are there, the type is image/png, whatever the file is called. JPEG, GIF, WebP, AVIF, ICO and BMP each have a signature like this, and SVG is recognised by its opening svg tag.

Next, the encoding. Base64 takes the bytes three at a time, 24 bits, and splits them into four groups of 6 bits. Each 6-bit group is a number from 0 to 63, and each number is a character from A to Z, a to z, 0 to 9, + or /. Seventy bytes are 23 full groups of three with one byte left over. The 23 groups make 92 characters, and the last byte is padded out to make 4 more, two of them = signs. So the 70-byte file becomes 96 characters of Base64. Put "data:image/png;base64," in front, 22 characters, and the whole data URL is 118 characters long.

That ratio is the cost of the method. 96 characters for 70 bytes is 4 for every 3, about 37% more here because of the padding on such a small file, and closer to exactly 33% on larger ones. For this pixel it does not matter: 118 characters inside a stylesheet is far cheaper than a separate HTTP request, which carries hundreds of bytes of headers and a round trip to the server. That is the case data URLs were made for.

Scale it up and the trade turns around. A 200 KB photo becomes about 267 KB of text, inside your HTML or CSS. It cannot be cached separately, so it is downloaded again every time that file is. It cannot start loading until the file around it has been read. And it makes the file harder to read and review. The page warns you when the result is large for this reason. A rough rule: inline what is a few kilobytes or less and needed for the first paint, and serve everything else as a normal file.

Two more limits. SVG is already text, so Base64 makes it bigger for no reason; a URL-encoded SVG data URL is usually shorter. And many email clients strip data URLs, so they are a poor fit for HTML email. All of the reading and encoding here happens in your browser. The image never leaves your device.

Frequently asked questions

Is my image uploaded to convert it?

No. The browser reads the file on your device and does the encoding on this page. Nothing is sent anywhere, and it works offline.

Why is the Base64 text bigger than my image?

Base64 uses 4 characters for every 3 bytes, so the text is about 33% larger than the file. Gzip on the server wins back a little of that, but never all of it.

Which image types work?

PNG, JPEG, GIF, WebP, AVIF, SVG, ICO and BMP. The type is detected from the file’s contents, so a wrong or missing file extension does not matter.

When is inlining an image a good idea?

When the image is tiny and needed straight away, such as an icon in critical CSS, saving a request is worth the extra bytes. For anything over a few kilobytes, a separate file that the browser can cache is usually faster.

Can I turn Base64 back into an image here?

Not on this page. Paste a data URL into your browser’s address bar and it will show the image, which you can then save.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.