Image to Base64: What It Is and How to Convert

Published Sep 8, 2026

By The ImageTools Pro team · Last reviewed Sep 8, 2026

Base64 lets you embed images directly inside HTML, CSS, or JSON — no separate file. Learn what Base64 is and how to convert any image to Base64 online.

Image to Base64: What It Is and How to Convert

Base64 encoding turns an image into a text string you can paste directly into HTML, CSS or a JSON field. No separate file, no upload step, no broken image path. The trade-off is size: the string is always about a third larger than the original bytes. Here is how it works, when it helps, and how to avoid the mistakes that make an embedded image fail.

What Base64 actually does

Base64 represents binary data using 64 printable characters. Every 3 bytes of the source become 4 characters of output, which is where the 33% overhead comes from. If the input length is not divisible by 3, the encoder adds padding characters at the end.

A complete data URI has two parts: a prefix that declares the MIME type, and the encoded payload. The prefix looks like data:image/png;base64, followed by the string. Without the prefix, a browser treats the text as an ordinary string, not as an image.

Image typeMIME prefix
JPEGdata:image/jpeg;base64,
PNGdata:image/png;base64,
WebPdata:image/webp;base64,
GIFdata:image/gif;base64,
SVGdata:image/svg+xml;base64,

The real cost, measured

Base64 is not compression. It is an encoding, and it makes the payload bigger. These figures use our own fixture files and the standard 4-characters-per-3-bytes rule.

FileOriginal sizeBase64 charactersWith prefixOverhead
Transparent logo129,117 bytes172,156172,17833%
Screenshot197,518 bytes263,360263,38233%
12 MP photo1,360,339 bytes1,813,7881,813,81033%

For ASCII text, one character is one byte in UTF-8, so those character counts are also byte counts. The 12 MP photo becomes a 1.8 MB string before it is pasted into anything. That is fine for a build step and painful for a hand-edited HTML file.

When Base64 helps

SituationVerdictWhy
Small logo inside a CSS fileGoodRemoves one request and keeps the asset with the style
Single-file HTML demoGoodOne file really does contain everything
Favicon or tiny iconGoodThe overhead is a few hundred bytes
JSON field for a small imageWorkableThe alphabet has no quotes or backslashes, so it needs no escaping
Large photo in a pageBadAdds 33% to an already heavy asset and blocks caching
The same image on many pagesBadThe string is repeated in every document instead of being cached once
Email signatureTest itSome email clients and security filters block data URIs

The caching point is the one people miss. A normal image file is downloaded once and reused from the browser cache. An inline data URI travels with every HTML or CSS document that contains it, and it cannot be cached as a separate resource.

How to convert an image to Base64

  1. Open Image to Base64.
  2. Drop a JPG, PNG, WebP or GIF file.
  3. Click Convert to Base64.
  4. Copy the full result, including the data: prefix.
  5. Paste it into the target attribute or download it as a text file.
  6. Open the page and confirm the image renders before you ship it.

Pasting it correctly

  • HTML: put the entire string in the src attribute of an img tag. Do not add a file path or a second prefix.
  • CSS: use the string inside a quoted url value for background-image. The Base64 alphabet includes plus, slash and equals, all of which are safe inside quotes.
  • JSON: paste the string as a normal JSON string value. Base64 contains no double quotes or backslashes, so it does not need escaping.
  • No line breaks: a wrapped string is still valid in some parsers but breaks in others. Keep it on one line.

Common failures

  • Missing prefix. The payload alone is not a data URI. The browser needs the MIME declaration.
  • Truncated string. Base64 payloads have a length that is a multiple of four, including padding. One missing character can break the whole decode.
  • Wrong MIME type. Declaring a PNG as image/jpeg may render in a forgiving browser and fail in a strict consumer.
  • Copied from a terminal that wrapped the line. Remove the newlines before pasting.
  • Double encoding. Encoding an already encoded string produces a much larger payload that no browser can display.
  • Using it for a multi-megabyte photo. The page becomes heavier than the image ever was as a separate file.

A quick validation checklist

  1. Does the string start with data:image/ and the correct subtype?
  2. Is the payload free of spaces and line breaks?
  3. Is the total payload length a multiple of four?
  4. Does the image render in the target browser, email client or app?
  5. Did you keep the original file for future edits?

For the complete reference, including how the encoding maps to bytes and how to validate a data URI, read the Image to Base64 guide.

Convert your first image now: Image to Base64

We value your privacy

This site is ad-supported by a partner that may set a cookie to personalize ads. Reject and no third-party ad scripts load at all. All image processing stays 100% in your browser either way.