Skip to content
ToolkitHub

Image to Base64

Convert images to Base64 data URIs and back

Guide

Encoding images as Base64 data URIs

By Logappradeep · ServiceNow developer

Base64 turns binary data, such as the bytes of a PNG file, into plain text made of letters, digits, plus and slash. Text can be pasted anywhere text goes: into HTML, CSS, JSON, an email template or a configuration file. Wrapped in a data URI, a Base64 image can be used without a separate file or network request.

What a data URI looks like

A data URI starts with the scheme, the media type and the encoding, followed by the encoded bytes:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...

The tool generates this for you, along with snippets you can paste straight into your code:

<img src="data:image/png;base64,..." alt="">

.icon { background-image: url("data:image/png;base64,..."); }

The 4/3 size overhead

Base64 represents every 3 bytes of binary data with 4 text characters, each carrying 6 bits. That makes the encoded text about 33 percent larger than the original file, plus up to two = padding characters. A 30 KB image becomes roughly 40 KB of text. Gzip or Brotli compression on a web server recovers some, but not all, of that overhead.

When inlining makes sense

  • Small icons and decorative images of a few kilobytes, where saving an HTTP request matters more than the extra bytes.
  • HTML email signatures and templates, though note that some email clients block data URIs; test before relying on it.
  • Self-contained files, such as a single HTML report, a test fixture or a JSON payload that must carry an image.
  • Prototypes and code samples where you do not want to host an image file.

When to avoid it

Large photos should stay as separate files. Inlined images cannot be cached independently by the browser, so they are downloaded again with every page or stylesheet that contains them, and they make HTML and CSS slower to parse. As a rule of thumb, keep data URIs under about 10 KB.

Decoding Base64 back to an image

Paste a Base64 string or full data URI and the tool shows the image and lets you download it as a file. This is useful for inspecting images embedded in API responses, emails or stylesheets. If the string has no media type prefix, the tool tries to detect the format from the decoded bytes.

Privacy and accuracy

Encoding and decoding use the browser's FileReader and built-in Base64 functions, so the image never leaves your device. Base64 is an encoding, not encryption: anyone can decode it, so never treat it as a way to hide content. Optimize the image with the compressor before encoding, because every byte saved shrinks the Base64 string by a third more.

Frequently asked questions

Why is the Base64 text bigger than my image?

Base64 uses 4 characters for every 3 bytes, so encoded data is about 33 percent larger than the original file.

Is Base64 a way to protect or hide an image?

No. It is a reversible encoding that anyone can decode, not encryption.

Should I inline every image as a data URI?

No. Inline only small images; larger ones are better served as separate files that browsers can cache.

Do data URIs work in email?

Support varies. Some email clients block data URI images, so test in the clients your recipients use.

Is my image sent to a server to encode it?

No. Encoding and decoding happen locally in your browser.