Image to Base64
How to convert an image to Base64
- Leave the direction on Image to Base64 and choose a file in the box above, or drop one on it.
- Pick the output: data URI, Base64 only, HTML img tag or CSS background-image.
- Read the three figures under the picture: file size, Base64 size and the growth.
- Click Copy result, or Save as .txt for a long string.
- To go back, switch the direction to Base64 to image and paste the text.
What this image to Base64 converter does
It wraps the bytes of your image in Base64 text and changes nothing else. No re-encoding happens, so a PNG stays the same PNG, only written as letters and digits. You get a data URI (data:image/png;base64,...), the bare Base64, a ready img tag with width and height filled in, or a CSS background-image line. The type comes from the file's first bytes, not its name, which is why a text file renamed to .png is refused with its name in the message.
A request log of one conversion showed 11 requests, none with a body and none containing the file's bytes or name. Only Google's ad and analytics servers were tried, and the test blocked them. For plain text Base64, not images, use Base64 encode and decode.
What Base64 costs you in size
Base64 turns every 3 bytes into 4 characters, so the text is a third bigger than the file. We checked it on seven files. Our 620,844 byte PNG became 827,792 characters of Base64, 33.33 percent more. A 42 byte GIF became 78 characters as a data URI.
Text compression recovers most of that. With gzip at level 9, the PNG's Base64 text came to 623,369 bytes against 620,844 for the file. If the server sends your CSS or HTML compressed, the extra weight is small. If it does not, you pay the full third.
When to put an image inline
Inline small things: a tiny icon, a one-pixel placeholder, an image in an email template that cannot link to a file. A data URI saves a request and keeps the picture inside the document that uses it. The cost is that the browser cannot cache it separately. The page warns above 1 MB: our 1.16 MB test file showed "This image is over 1 MB." For big pictures, use a normal file and shrink it first with the image compressor. We did not measure page speed.
The four output forms
On the 800 by 600 test PNG, the data URI was 827,814 characters. Plain Base64 was 22 fewer, the length of the prefix. The img tag, with width="800" height="600" and an empty alt, ran to 827,858 characters. The CSS line, background-image: url("..."); was 827,840.
SVG is already text, and Base64 does it no favours. Our 473 byte SVG became 632 characters, 34 percent more.
Base64 to image
Switch the direction, paste a data URI or bare Base64, and the picture appears with its type, size and pixel dimensions. Download image saves it with the right extension: image.png, image.jpg and so on. We decoded PNG, JPG, SVG, WebP and AVIF strings, and each download had the same SHA-256 as the original. Bare Base64, text wrapped at 76 columns and the URL-safe alphabet without padding decoded too.
Bad input gets a plain message. Random words give "This is not valid Base64." The string for the text "Hello world" is valid, so it says "This is valid Base64 (11 bytes) but it does not start like a PNG, JPG..." A cut-off file can slip through: the first 400 bytes of a PNG showed as a 600 by 600 PNG, because the browser read the header. Check the picture before you trust it.
Limits and what we did not test
One image at a time, up to 10 MB. A padded PNG of 11,106,604 bytes got "This file is over 10 MB." and no output. A PDF and a text file were refused by name. We tested PNG, JPG, GIF, WebP, AVIF and SVG. BMP and ICO are accepted but not measured, and we did not exercise the copy button or Save as .txt. The samples are synthetic and only Chromium was used.
Measured results
| File | File bytes | Base64 characters | Growth | Gzip of file | Gzip of Base64 |
|---|---|---|---|---|---|
| Photo PNG, 800 x 600 | 620,844 | 827,792 | 33.33% | 621,052 | 623,369 |
| Logo PNG, 600 x 600 | 21,105 | 28,140 | 33.33% | 20,374 | 20,669 |
| Photo JPG, 1280 x 960 | 247,358 | 329,812 | 33.33% | 247,157 | 247,523 |
| Logo GIF, 600 x 600 | 8,632 | 11,512 | 33.36% | 7,971 | 7,978 |
| Photo WebP, 1280 x 960 | 19,836 | 26,448 | 33.33% | 19,864 | 19,948 |
| Photo AVIF, 1280 x 960 | 19,912 | 26,552 | 33.35% | 19,919 | 19,968 |
| Shapes SVG, 400 x 240 | 473 | 632 | 33.62% | 298 | 446 |
Doing it in a build step instead
If you inline many images, a bundler or a build script can do it for you at build time, so you do not paste strings by hand. This page is for a one-off string, a quick check, or decoding a string someone sent you. Base64 adds a third to the size, so shrink the image first in IrfanView or XnView MP.
Frequently asked questions
Is my image uploaded?
No. The file is read and encoded in your browser tab. The request log from our test showed no request carrying a body, and none with the file's bytes or name.
How much bigger is Base64 than the image?
A third bigger. Our 620,844 byte PNG became 827,792 characters. Every test file grew by 33 to 34 percent.
Should I use Base64 images in CSS?
For tiny icons, yes. For anything over about 1 MB, no: the string cannot be cached on its own, and the page warns you at that size.
Can I turn Base64 back into an image?
Yes. Switch to Base64 to image, paste a data URI or plain Base64, and download the file. In our test the SHA-256 matched the original.
Why does it say the Base64 is not valid?
The text has characters outside the Base64 alphabet, or it was cut off. Copy the whole string again.
Is there a size limit?
10 MB per image, one image at a time. Above 1 MB you get a note that a normal file is usually better.