Skip to main content
ponderloop

Image to Base64 Converter

Choose or drop an image to get its Base64 data URI, the raw Base64 and ready-to-paste HTML, CSS and Markdown snippets, with exact sizes. The built-in example, a 16 × 16 PNG, shows the result: 216 bytes become 288 Base64 characters (+33.3%), or 310 as a data URI. The image type is read from the file’s first bytes (PNG, JPEG, GIF, WebP, SVG, AVIF or ICO), not from its name, so the data URI carries the right MIME type. To go the other way, paste a data URI or plain Base64 and the tool previews the image and lets you download it. Files up to 5.0 MB are read in your browser and never uploaded.

Updated Runs in your browser: nothing you enter is uploadedHow this tool works

Image to Base64

Stays in your browser

216 bytes become 288 Base64 characters (+33.3%), or 310 as a data URI.

Preview of your file
Detected type
PNG image (image/png)
Image file
216 bytes
Base64 text
288 characters
Data URI
310 characters
Base64 overhead
+33.3% (72 bytes more)

Base64 to image

Decoded 216 bytes from data URI: PNG image.

Preview of the decoded data
Detected type
PNG image (image/png)
Decoded size
216 bytes
Base64 characters
288

How each image type is recognised

The tool checks these signatures, in this order, and uses the matching MIME type in the data URI. A file name or the browser’s own guess never overrides them.
FormatMIME typeUsual extensionWhat the tool looks for
PNGimage/png.pngFirst 8 bytes 89 50 4E 47 0D 0A 1A 0A (“\x89PNG” and a line-end check)
JPEGimage/jpeg.jpgFirst 3 bytes FF D8 FF
GIFimage/gif.gifText “GIF87a” or “GIF89a” at the start
WebPimage/webp.webpText “RIFF” at byte 0 and “WEBP” at byte 8
AVIFimage/avif.avifText “ftyp” at byte 4, then brand “avif” or “avis” (major or compatible)
ICOimage/x-icon.icoBytes 00 00 01 00, then an image count of 1 or more
SVGimage/svg+xml.svgText: an “<svg” tag after optional BOM, XML declaration, comments and DOCTYPE

How much bigger the Base64 form is

Every 3 bytes become 4 characters, so Base64 is about 4/3 of the file (+33.3%). A data URI adds the “data:image/png;base64,” prefix on top. Sizes here are for a PNG.
Image file (bytes)Base64 charactersData URI charactersBase64 overhead
1,0001,3361,358+33.6%
10,00013,33613,358+33.4%
100,000133,336133,358+33.3%
1,000,0001,333,3361,333,358+33.3%

Which form to use where

FormUse it forWatch out for
Data URIAnywhere a URL is accepted: img src, CSS url(), JSON, e-mail templatesIt is part of the file it sits in, so the browser cannot cache the image on its own
Raw Base64APIs and JSON fields that take image bytes and ask for the type separatelyNo type information: the receiver must know it is a PNG, JPEG and so on
HTML <img> tagA small icon or logo inside a single self-contained HTML file or e-mailAdd real alt text for anything that is not purely decorative
CSS background-imageSmall repeating patterns and icons in a stylesheetA big data URI makes the whole stylesheet slower to download and parse
Markdown imageSelf-contained notes and README files that cannot link to a separate imageSome Markdown renderers and sites block data: URIs

How to convert an image to Base64

  1. Choose the image. Press “Choose an image, or drop it here” and pick a file, or drag one onto the box. Files up to 5.0 MB work; nothing is uploaded.
  2. Check the type and sizes. The detected type, the exact byte count of the file and the length of the Base64 text and data URI appear next to the preview.
  3. Copy the form you need. Copy the data URI, the raw Base64, or a ready HTML <img> tag, CSS background-image rule or Markdown image.
  4. Add alt text. The HTML and Markdown snippets have an empty alt. Fill it in if the image carries meaning.
  5. Go the other way if you need to. In “Base64 to image”, paste a data URI, a snippet that contains one, or plain Base64 to see the picture and download it as a file.

Frequently asked questions

What is a data URI?
A data URI puts a file’s content inside the URL itself, in the form data:<type>;base64,<data>. Browsers treat it like any image address, so it works in an img src, a CSS url() or a Markdown image without a separate file.
Why is the Base64 text bigger than my image?
Base64 writes every 3 bytes as 4 characters, so the text is about 33% longer than the file, and a little more for very small files because of padding. The data URI adds its “data:image/png;base64,” prefix on top. The tool shows the exact counts, and the table above lists examples.
How does the tool know the image type?
It reads the first bytes of the file. A PNG starts with 89 50 4E 47 0D 0A 1A 0A, a JPEG with FF D8 FF, a GIF with “GIF87a” or “GIF89a”, a WebP with “RIFF” and “WEBP”, an AVIF with an “ftyp” box naming avif or avis, an ICO with 00 00 01 00, and an SVG with an <svg> tag. If the file name or the browser says something else, the bytes win and the tool tells you.
When should I not use a Base64 image?
For anything large or reused on many pages. Because the image is inside the page or stylesheet, it cannot be cached separately, it makes that file about a third larger, and it delays rendering. It suits small icons, logos and one-file documents; a normal image file is better for photos.
Can I turn Base64 back into an image?
Yes. Paste a data URI, a whole HTML, CSS or Markdown snippet that contains one, or plain Base64 into “Base64 to image”. The tool decodes it, shows a preview, names the detected type and offers the file as a download. Percent-encoded SVG data URIs (data:image/svg+xml,%3Csvg…) work too.
Does it work with SVG?
Yes. An SVG is text, so it is recognised by its <svg> tag, even after an XML declaration, comments or a DOCTYPE. It is shown as an image, so scripts inside it do not run. For SVG you can often use a shorter percent-encoded data URI instead of Base64; this tool produces the Base64 form.
Why does the page say the file is not recognised?
The file does not start with any of the seven signatures the tool knows. It may be another format (BMP, HEIC, TIFF), a renamed file or damaged. It is still encoded, using the type your browser reported or application/octet-stream, but browsers may not display it as an image.
Is my image uploaded or saved?
No. The file is read by your browser and converted on this page, nothing is sent to a server and nothing is stored: reload the page and it is gone. If you allow analytics, the site records only that a button was used, never the image, its name, size or type.
Do I need to allow data: images in my site’s security policy?
If your site sets a Content-Security-Policy, add data: to the img-src directive (and to style-src or default-src where a CSS background needs it). Without it, the browser blocks data URI images even when the Base64 is correct.

How it works

The chosen file is read into memory with FileReader as raw bytes. The type is detected from the first bytes: the 8-byte PNG signature, FF D8 FF for JPEG, GIF87a or GIF89a, RIFF…WEBP, an ISO base media “ftyp” box whose major or compatible brand is avif or avis, an ICO header (00 00 01 00 and at least one image), and, for SVG, an <svg> root tag after any BOM, XML declaration, comments and DOCTYPE. The bytes are encoded with the same Base64 encoder as the Base64 Encode & Decode tool (standard alphabet, “=” padding, no line breaks), and the data URI is “data:” plus the detected MIME type plus “;base64,” plus that text. Sizes are exact: the Base64 text has 4 × ceil(bytes / 3) characters, and overhead is that count against the file’s byte count. In the reverse direction, a pasted data URI (Base64 or percent-encoded) or the first data URI inside a snippet is decoded, or, if there is none, the whole text is decoded as Base64 with the same tolerant decoder (whitespace ignored, either alphabet, padding optional). The preview and download are made from the decoded bytes with the detected type.

Sources

More: Web, URLs, images and networkAll developer toolsAll toolsHome & DIY calculators