🖼️ Data URI Encoder

Image to Base64 & Base64 to Image Converter

Convert image files directly into inline HTML/CSS Data URI Base64 strings, or decode Base64 strings back to downloadable image files.

How Base64 encoding works

Base64, defined in RFC 4648, turns arbitrary bytes into plain text using 64 safe characters: A to Z, a to z, 0 to 9, plus and slash. It reads the input three bytes at a time, which is 24 bits, splits those bits into four groups of six, and maps each six-bit value to one character.

Worked example: the three ASCII bytes of the word Man are 77, 97 and 110. In binary that is 010011 010110 000101 101110, which maps to the characters T, W, F and u, so Man becomes TWFu. When the input length is not a multiple of three, the output is padded with equals signs: Ma becomes TWE= and M becomes TQ==.

Because every 3 bytes become 4 characters, Base64 output is one third larger than the input. A 3,000 byte PNG becomes exactly 4,000 characters of Base64, and 4,022 characters once the 22 character prefix data:image/png;base64, is added.

Anatomy of a data URI

A data URI, specified in RFC 2397, packs a whole file into a URL. It has three parts: the scheme data:, a media type such as image/png, and the payload, marked as Base64 with ;base64 before the comma. Browsers treat it exactly like a link to a file, so it works in an img src, a CSS url() value, or anywhere else a URL is accepted.

This tool reads your file with the browser's FileReader and returns the complete data URI, using the media type the browser reports for the file. The conversion runs locally; the image is not uploaded. Decoding works the other way round: paste either a full data URI or a bare Base64 string. For a bare string the tool reads the first bytes to recognise PNG, JPEG, GIF, WebP or SVG, builds the matching data URI, and names the download with the correct extension. base64url characters (- and _) are converted to the standard alphabet automatically.

When inlining helps and when it hurts

Inlining saves one HTTP request per image. Under HTTP/1.1, where browsers opened only a handful of connections per host, that was a real gain for small icons. With HTTP/2 and HTTP/3 multiplexing many requests over one connection, the saving is much smaller, while the costs remain.

  • Size: the 33 percent overhead is only partly recovered by gzip or Brotli on the surrounding HTML or CSS.
  • Caching: an inlined image is cached only as part of its parent file. Change one line of CSS and every embedded icon downloads again.
  • Render blocking: images inlined into a stylesheet delay first paint, because the browser must download the whole CSS file before drawing anything.
  • Good candidates: tiny icons and placeholders of a few kilobytes, images inside single-file HTML exports, and fixtures in tests or JSON payloads.
  • Poor candidates: photos, hero images and anything shared across many pages, which are better served as normal cacheable files.

Practical tips for developers

For SVG icons, skip Base64. SVG is already text, so a URL-encoded form such as data:image/svg+xml,%3Csvg ... is usually smaller than its Base64 equivalent and still readable in the source.

Base64 is an encoding, not encryption. Anyone can decode the string, so never treat it as a way to hide an image or a credential.

If an API returns base64url, the variant that uses - and _ instead of + and /, convert those characters back to standard Base64 before putting the string in a data URI, because browsers only accept the standard alphabet there.

Many email clients block or strip data URI images, especially in the message body. For newsletters, linked images or attachments referenced with a content ID are more dependable.

Image to Base64: frequently asked questions

Why is the Base64 string bigger than my image file?

Base64 represents every 3 bytes with 4 text characters, so the output is about 33 percent larger before the data URI prefix is added. A 10 KB image becomes roughly 13.3 KB of text.

Is Base64 the same as encryption?

No. It is a reversible encoding with no key, designed to carry binary data through text-only channels. Anyone with the string can decode it in seconds.

What do the equals signs at the end of a Base64 string mean?

They are padding. When the input length is not divisible by three, one or two = characters are added so the output length stays a multiple of four. One = means the last group held two bytes; two mean it held one.

What is the maximum length of a data URI?

Modern desktop browsers handle data URIs of many megabytes, but older browsers had limits as low as 32 KB, and very long strings make HTML and CSS slow to parse and hard to edit. In practice, keep inlined images small.

Should I inline images in CSS for performance?

Only very small, rarely changing images. For anything larger than a few kilobytes, a separate file that the browser can cache and load in parallel is usually faster on HTTP/2.

All image & media suite