Image to Base64 Converter (and Back)

Turn an image into Base64 text for HTML, CSS or JSON, or paste Base64 and download the picture it contains.

  • Nothing is uploaded
  • No sign-up
  • No watermark

Drop an image here, choose one, or paste with Ctrl+V

Choose an image

PNG, JPG, SVG, WebP, GIF, ICO and other files up to 25 MB.

Files stay on your device. Nothing is uploaded.

Base64 is a way of writing any file using only 64 safe characters: A to Z, a to z, 0 to 9, plus and slash. Systems that only expect text, such as HTML attributes, CSS files, JSON documents and email bodies, can carry an image written this way without the bytes getting mangled. Add a short header and you get a data URL, which a browser treats just like a link to an image file.

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

The part before the comma says what kind of file follows. The rest is the file itself, in Base64.

Encoding an image

  1. Leave the switch on Image to Base64 and add a file, or paste a copied image.
  2. The data URL and the plain Base64 appear in two boxes, with the character count and size increase above them.
  3. Use the copy buttons. Copy as <img> tag and Copy as CSS background give you ready-to-paste snippets.

The type in the data URL comes from the file itself. If your browser does not report one, the tool reads the first bytes of the file to work it out, which is why a PNG saved with the wrong extension still gets the right image/png header.

The 33% rule

Every 3 bytes of the file become 4 characters of Base64. A 3,000-byte icon turns into 4,000 characters, and a 30 KB image (30,720 bytes) into 40,960. A 1 MB photo becomes almost 1.4 million characters of text. The formula, if you want it:

Base64 length = 4 × ceil(file size in bytes ÷ 3)

That overhead is fine for small things and costly for big ones. Gzip compression on a web server wins some of it back, but not all of it.

When inline images make sense

A data URL saves the browser a separate request for the image. That helps for tiny, essential images, such as a small logo in a single-file HTML page, an icon in a CSS file, or a placeholder shown while a larger photo loads. It is also how images are stored inside many JSON APIs and exported notebooks.

It hurts for anything sizeable. An inline image cannot be cached on its own, so it is downloaded again with every page or stylesheet that contains it, and it delays the HTML or CSS around it. As a rough guide, keep inline images to a few kilobytes and serve everything else as normal files. If you are inlining SVG icons, the SVG text itself can often be used without Base64 at all, which is smaller.

Decoding Base64 back to an image

Switch to Base64 to image and paste. The tool accepts:

  • a full data URL, or a CSS url("data:...") value copied from a stylesheet
  • bare Base64, with or without line breaks
  • the URL-safe variant that uses minus and underscore instead of plus and slash
  • text with the trailing = padding missing

It decodes the text, checks the first bytes to identify the format, shows a preview and the pixel size, and offers the file for download with the right extension. If the header claims one type but the data is another, it tells you. Text with stray characters or a missing chunk gets a specific error pointing to the problem, which is usually a copy that was cut short.

Base64 in JSON and APIs

Web services that accept images inside JSON usually want the bare Base64, without the data:image/png;base64, part, often in a field with a name like image or content. Others ask for the full data URL. Check the service's documentation, then copy from the matching box. Sending the data URL where bare Base64 is expected is one of the most common reasons an upload is rejected with "invalid image".

Line breaks

Email standards (MIME) wrap Base64 at 76 characters per line, and some older tools expect that. Tick Split the Base64 into 76-character lines for those. Browsers and most programming languages accept unbroken Base64, so leave it off for data URLs.

Privacy

Encoding and decoding both happen in this browser tab. The image you encode and the text you paste are not uploaded or stored, so it is fine to decode an image from a private chat log or an API response.

For icons, a PNG rendered from your SVG or a compressed copy from the image compressor will keep the Base64 short.

Frequently asked questions

Why is the Base64 text bigger than the image?

Base64 uses 4 text characters for every 3 bytes, so it is always about 33% larger than the file, plus the short data URL header.

Should I put Base64 images in my website?

Only small ones, such as icons of a few kilobytes. Large inline images cannot be cached separately and make your HTML or CSS heavier to download and parse.

Why does my decoded file say it is not an image?

The pasted text decoded correctly but the bytes do not start like any image format the tool recognises. It may be a different kind of file, or the text may have been cut off. You can still download it as a .bin file.

Do Base64 images work in emails?

Support is patchy. Several popular email services and apps do not display data URL images, so attached or linked images are more reliable for newsletters.