Image to Base64 and back

Turn an image into a Base64 string or data URI with HTML, CSS and Markdown snippets, or paste Base64 and get the picture back.

loading Image to Base64 and back
About this tool

What is image to Base64 conversion?

Converting an image to Base64 means writing its bytes as plain text made of letters, digits, + and /, so the picture can live inside an HTML, CSS, JSON or Markdown file instead of being a separate download. Put the prefix data:image/png;base64, in front and you have a data URI, which a browser accepts anywhere it accepts an image address: <img src="data:...">, background-image: url("data:..."), an email template, a JSON payload.

This tool does both directions. In Image to Base64 you drop a picture and get the Base64 text with ready-to-copy HTML, CSS and Markdown snippets. In Base64 to image you paste a Base64 string or a full data URI and get the picture back, with a preview and a download button.

People use it to inline a tiny icon so a page needs one request fewer, to embed a logo in an email template, to put an image in a JSON API field, or to find out what a long data:image/... string found in someone's code actually shows. Base64 is an encoding, not compression and not encryption: anybody can decode it, and the text is about a third larger than the file.

Everything runs in your browser. The picture is read and converted on your device, nothing is uploaded, and there is no account, no watermark and no limit set by this site; only your device's memory.

How to convert an image to Base64

  1. Open the Image to Base64 tab, then drop a picture on the page, click the file button or paste one with Ctrl+V. JPG, PNG, WebP, GIF, BMP, SVG and AVIF are accepted. An example image is loaded first, so you see a result immediately.
  2. Leave Include the data: prefix (data URI) ticked if you want a string that works directly in src or url(). Untick it for the bare Base64, which is what many APIs and JSON fields expect.
  3. Click Generate Base64. The text appears in a box together with its length in characters.
  4. Press Copy for the text exactly as shown, or HTML, CSS or Markdown for a finished snippet: <img src="..." alt="">, background-image: url("..."); or ![](...). The three snippets always use the full data URI.
  5. To go the other way, open Base64 to image and paste into Paste Base64 or a data URI. Spaces and line breaks are ignored, and the URL-safe alphabet (- and _) is accepted. The image and its type and size appear; press Download to save it.

Examples

Size of the result

Base64 turns every 3 bytes into 4 characters, so the text is about 33% longer than the file.

FileBase64 characters
1,000 bytes (a small icon)1,336
12,000 bytes16,000
1 MB (1,048,576 bytes)1,398,104

On top of that, the prefix adds 22 characters for a PNG (data:image/png;base64,) and 26 for an SVG. Above 1 MB the tool warns that inlining slows a page down.

A small icon inside CSS

arrow.png, 16 × 16, 300 bytes. With the prefix ticked, press CSS and paste the result into your stylesheet: the icon is now part of the CSS file and needs no extra request. This pays off for tiny, rarely changing images only.

Recognising the format from the first letters

Every format starts with the same bytes, so its Base64 starts with the same letters:

Starts withFormat
iVBORw0KGgoPNG
/9j/JPEG
R0lGODGIF
UklGRWebP (RIFF container)
PHN2ZySVG (<svg)

When you paste bare Base64 without the prefix, the tool uses these signatures to find the type.

Opening a string you found in code

Paste data:image/svg+xml;base64,PHN2Zy... into Base64 to image. You get the drawing, the line image/svg+xml with its size, and a download as image.svg.

Common errors and how to fix them

  • "This is not valid Base64 or a data URI. Check for missing or extra characters.": the text has characters outside the Base64 alphabet, or part of it was cut off when copying. Copy the whole string again.
  • "This text is valid Base64, but it is not an image.": the bytes decoded fine but are not a picture, or the format could not be recognised. For AVIF, paste the full data URI with data:image/avif;base64, in front, because bare Base64 of that format is not detected.
  • The snippet is gigantic: an image over 1 MB produces over 1.3 million characters. Compress or resize it first with Compress image or Resize image.
  • The data URI does not show in an email: several mail clients block data URIs. Host the image and link it instead.

Frequently asked questions

Is it a good idea to put images in Base64 inside HTML or CSS?

Only for very small images, such as icons and one-colour logos. Base64 is a third larger, the browser cannot cache the image separately from the page, and a big string makes the file hard to read. For anything above a few KB a normal file served with caching is better.

Does converting to Base64 reduce the file size?

No, the opposite: it grows by about 33%. Base64 only makes binary data safe to carry as text. To shrink a picture, compress it first.

Is my image uploaded to a server?

No. The conversion runs in your browser, in your device's memory. The page makes no request with your image.

How do I turn a Base64 string back into a picture?

Open Base64 to image, paste the string with or without the data: prefix and download the result. If the string is not an image, the tool says so.

Can I convert text or a PDF to Base64 here?

This page is for images. For any text or file, use Base64 encode and decode and Base64 decode.

Does it work on my phone?

Yes, it works in any current mobile browser; pick a photo from the gallery or paste one.

Report a problem