Image to Base64 Converter - Encode Images to Base64 Online
Turn a PNG, JPEG, GIF, WebP, SVG or ICO file into a Base64 string for a data URI, a CSS background or a JSON field. The file is read in your browser and is not uploaded.
Loading Image to Base64 Converter...
How to Convert an Image to Base64
Pick Your Image
Click the "Upload" button or drag the file onto the left panel. Any common web image works, from a PNG screenshot to an SVG logo or a favicon.ico.
Check the Format and the Output
Encoding starts as soon as the file has been read. The Base64 string fills the editor on the right, and the left panel shows a preview, the file size and the format taken from the file's own header.
Copy or Download the String
"Copy" puts the string on your clipboard and "Download" saves it as a .txt file named after the image. Both hold exactly what the editor shows. "Reverse" opens Base64 to Image in a new tab if you want to check the round trip.
<img src="data:image/png;base64,..." alt="...">Data URI Prefixes and How Each Format Starts
The first characters of a Base64 image give its format away, which helps when you find a string in a database or a log and wonder what it is.
| Format | Data URI prefix | Base64 starts with |
|---|---|---|
| PNG | data:image/png;base64, | iVBORw0KGgo |
| JPEG | data:image/jpeg;base64, | /9j/ |
| GIF | data:image/gif;base64, | R0lGOD |
| WebP | data:image/webp;base64, | UklGR |
| SVG | data:image/svg+xml;base64, | PHN2Zy or PD94bWwg |
| ICO | data:image/x-icon;base64, | AAABAA |
| BMP | data:image/bmp;base64, | Qk |
Should You Inline Images as Base64?
Inlining saves one request, and that is about all it saves. Base64 makes the image roughly 33% bigger, and the browser can no longer cache it separately: the bytes travel again with every page or stylesheet that contains them.
It pays off for small, single-use pictures such as a loading spinner, a tiny SVG icon in a stylesheet, an image inside a self-contained HTML report, or an image an API insists on receiving as text. For photos, hero images and anything shared across pages, a regular image file is faster.
Frequently Asked Questions
Which image formats can I encode here?
PNG, JPEG, GIF, WebP, BMP, ICO (and CUR cursors), SVG, TIFF and AVIF. The page looks at the first bytes of the file to work out the format, so the label you see next to the file size is what the file really is, not what its name claims. HEIC photos are the one exception: they are turned into a JPEG first, so you get the Base64 of that JPEG rather than of the original HEIC file.
What is the difference between a data URI and plain Base64?
Plain Base64 is just the encoded characters, which is what the output panel shows and what Copy and Download give you. A data URI puts a short header in front so a browser knows what it is looking at: data:image/png;base64, followed by the string. Use the data URI in an img src or a CSS url(), and the plain string when an API or a JSON field asks for Base64 on its own.
How do I know which data URI prefix to use?
Match it to the format shown next to the file size: data:image/png;base64, for PNG, data:image/jpeg;base64, for JPEG, data:image/gif;base64, for GIF, data:image/webp;base64, for WebP and data:image/svg+xml;base64, for SVG. If a file has the wrong extension, say a PNG saved as photo.jpg, the page encodes it as it is and shows a note with the prefix that fits the real format.
When is a Base64 image a bad idea?
When the image is big or used on more than one page. The string is about a third larger than the file, it has to be downloaded again with every HTML or CSS file it sits in, and the browser can't cache it on its own. A 2 KB icon or a 1x1 tracking pixel is a fine candidate. A 400 KB product photo is better served as a normal file.
Will the decoded image be identical to my file?
Yes, for every format except HEIC. The page encodes the file byte for byte, with no resizing, re-compression or metadata stripping, so transparency, animation frames, ICO sizes and any EXIF data stay inside the string. Paste it into Base64 to Image and you get back the same file you uploaded.
What happens if I upload something that is not an image?
A text file, PDF, ZIP or GZIP archive is refused with a short message that says what the file looks like, even if it was renamed to .png. An empty file is reported as empty. For files that really aren't images, File to Base64 encodes anything.
How large can the image be?
Up to 10 MB. Keep in mind that a 10 MB image becomes roughly 13.3 MB of text, which is far too much to paste into HTML or a JSON request comfortably.
Is my image uploaded anywhere?
No. Your browser reads the file and builds the Base64 string on your own machine; the image is not sent to a server and nothing is kept, so a reload starts with an empty panel. SVG files are shown in the preview as a plain image, so any script inside them does not run.
To turn a string back into a picture, use Base64 to Image. There are also pages written around a single format, such as PNG to Base64, JPG to Base64 and SVG to Base64, and File to Base64 handles files that aren't images.
Related Tools
Base64 to Image
Decode Base64 encoded strings to view and download images (PNG, JPG, GIF, SVG)
PNG to Base64
Convert PNG images to Base64 encoded strings for embedding
Base64 to PNG
Decode Base64 strings to PNG images, see the picture and save the exact file
BMP to Base64
Convert BMP/Bitmap images to Base64 encoded strings
Base64 to BMP
Decode Base64 strings to BMP/Bitmap images
Base64 to WebP
Decode Base64 strings to WebP images with transparency