Image to Base64 Converter
Published Updated
Turn an image into one line of Base64 text, or tick a box for a full data:image/...;base64, URL to paste into HTML or CSS. The text runs to 4 characters per 3 bytes, so a 30,000-byte icon gives 40,000 characters.
Bare Base64 or a data: URL
The tool reads the image with FileReader.readAsDataURL, which returns a complete data: URL, and by default shows only the part after the comma. Tick Include Data URL prefix and you get the full form that RFC 2397 defines, data:[<mediatype>][;base64],<data>, ready for markup.
The media type in that prefix is not read from the image bytes. MDN's File.type page notes that browsers take it from the file extension, so a PNG renamed photo.jpg is labelled image/jpeg.
The prefix each file name receives
Measured by picking one file under each name in a real file input, then reading it the way the tool does:
| File name ends in | Google Chrome 156 | Firefox 155 | WebKit 26.6 |
|---|---|---|---|
| .png | image/png | image/png | image/png |
| .jpg or .jpeg | image/jpeg | image/jpeg | image/jpeg |
| .jfif | image/jpeg | image/jpeg | application/octet-stream |
| .svg | image/svg+xml | image/svg+xml | image/svg+xml |
| .ico | image/vnd.microsoft.icon | image/x-icon | image/x-icon |
| .heic | image/heic | image/heic | image/heic |
| no extension | application/octet-stream | application/octet-stream | application/octet-stream |
Where the string goes
- HTML:
<img src="data:image/png;base64,...">. The example in RFC 2397 itself is a small GIF inside an IMG tag. - CSS:
background-image: url("data:image/svg+xml;base64,..."). - JSON and most APIs: the bare string without the prefix, which is what the MDN page above says to keep when only Base64 is needed.
Encoding an image
Step 1
Add the image
The page opens in File and Encode mode. Pick an image, or drop any file onto the box.
Step 2
Decide on the prefix
Leave Include Data URL prefix unticked for the bare Base64, or tick it for a data: URL that starts with the image type.
Step 3
Process and copy
Press Process. The string appears with its length in characters, and Copy to Clipboard puts it on your clipboard.
Size and limits
RFC 4648 encodes each 24-bit group of input as 4 characters, which is where the extra third comes from.
- RFC 2397 calls the scheme useful only for short values and says its own example image is probably near the limit of usefulness. Small icons and logos are the sweet spot.
- An image written into a page or stylesheet is not a separate file, so it cannot be cached on its own or shared by other pages; each page that holds it carries its own copy.
- Browsers do cap length: MDN's data: URL reference gives 512 MB for Chromium and Firefox and 2048 MB for Safari.
- Everything happens in memory, and the result sits in one scrolling box; in our test the 14,073,292-character string of a file the tool lists as 10.55 MB took about 1.9 seconds to appear in Chrome 156 and about 13 seconds in Playwright's WebKit build (not the Safari app); the timing table further down has the details.
Sixteen files encoded, then decoded back
We put generated test files into this tool's own file box in Chrome 156, Chromium 153 (Playwright build, not Google Chrome), Firefox 155 and the WebKit build. The browser gave each file its type from the name, as it does with a real file chooser. Each file was encoded without and with the prefix, the data: URL was pasted into the Decode side of the same tool, and the decoded file was compared with the original by SHA-256.
| File | Bytes | Base64 characters | Prefix the tool wrote | Decoded back |
|---|---|---|---|---|
| tiny.png | 178 | 240 | data:image/png;base64, | Same bytes, read as a PNG image |
| photo.jpg | 18,567 | 24,756 | data:image/jpeg;base64, | Same bytes |
| anim.gif (2 frames) | 6,349 | 8,468 | data:image/gif;base64, | Same bytes |
| pic.webp | 988 | 1,320 | data:image/webp;base64, | Same bytes |
| pic.bmp | 24,054 | 32,072 | data:image/bmp;base64, | Same bytes |
| icon.ico | 285 | 380 | data:image/vnd.microsoft.icon;base64, in the two Chrome builds, data:image/x-icon;base64, in Firefox and WebKit | Same bytes |
| vector.svg | 185 | 248 | data:image/svg+xml;base64, | Same bytes |
| pic.avif | 484 | 648 | data:image/avif;base64, | Same bytes |
| png-named.jpg (PNG bytes) | 178 | 240 | data:image/jpeg;base64, | Same bytes, saved as decoded.png with the warning The data URL says image/jpeg, but the bytes are a PNG image |
| jpeg-named.png (JPEG bytes) | 18,567 | 24,756 | data:image/png;base64, | Same bytes, saved as decoded.jpg with the matching warning |
| UPPER.PNG | 178 | 240 | data:image/png;base64, | Same bytes |
| A PNG with no extension | 178 | 240 | data:application/octet-stream;base64, | Same bytes, saved as decoded.png |
| doc.pdf | 329 | 440 | data:application/pdf;base64, | Same bytes, saved as decoded.pdf |
| Three noise PNGs | 1,054,390 / 10,554,969 / 26,382,300 | 1,405,856 / 14,073,292 / 35,176,400 | data:image/png;base64, | Same bytes, except the largest one in the WebKit build (see the timing notes) |
| empty.png | 0 | None | None | Refused: One or more files were empty (0 bytes) and couldn't be used |
The four engines agreed on every row except the .ico prefix and the largest file in the WebKit build. Every string had 4 characters for each 3 bytes, rounded up, and none had a line break. The counter under the result shows plain digits, such as 35176400 characters. The prefix added 22 characters for a PNG and 37 for the generic application/octet-stream one. The PDF shows that the box encodes whatever it is given: the image filter only narrows what the file chooser offers.
The prefix follows the file name, not the bytes, so the two mislabelled files carried the wrong type in their data: URL. The Decode side caught both, because it reads the type from the first bytes.
How long large images take
Time from pressing Process until the Base64 string was on the page, one run per engine, for the noise PNGs above (random generated pixels):
| Engine | 1,054,390 bytes | 10,554,969 bytes | 26,382,300 bytes |
|---|---|---|---|
| Chrome 156 | 205 ms | 1,858 ms | 7,536 ms |
| Chromium 153 | 205 ms | 1,642 ms | 4,021 ms |
| Firefox 155 | 231 ms | 2,099 ms | 4,731 ms |
| The WebKit build | 877 ms | 13,419 ms | 131,481 ms (a separate run with this file alone) |
Reading the file took at most 196 ms in every engine; the time goes into placing the long string on the page. Decoding the data: URL back took 22 to 39 ms for the file the tool lists as 1.05 MB and 276 to 377 ms for the 10.55 MB one. For the 26.38 MB file it took 612 to 2,230 ms in three engines. In the WebKit build, decoding that file back had not finished when the 10-minute limit of its run was reached; the first run with all 17 files had not finished this file within its 15-minute limit either.
Not tested: files above 26.38 MB (as the tool lists their size), real photos, the Copy to Clipboard button, and pasting the result into an HTML page or a stylesheet. Times depend on the device.
Image to Base64 FAQ
Should I tick Include Data URL prefix?
Tick it when the string goes straight into an src attribute or a CSS url(), which need the full data: URL. Leave it off for a JSON field or an API that asks for Base64 alone, and for any form that adds its own prefix. The box starts unticked.
Why does my data URL say application/octet-stream?
The type comes from the file name. A file with no extension, or one the browser does not recognise, has no type, so the generic label is used; in Safari a .jfif photo gets it too. Rename the file with the right extension and encode it again, or edit the start of the string by hand.
How long will the string be?
Four characters for every three bytes, rounded up, plus the prefix if you ask for it. A 4,183-byte PNG gives 5,580 characters, or 5,602 with data:image/png;base64, in front. A 10 MB photo gives about 13.3 million characters, which works but makes a heavy HTML or CSS file.
Does encoding change or shrink the image?
No. The file's bytes are copied exactly, so the string decodes to the same file, metadata included. A phone photo keeps its EXIF camera details and GPS position inside the Base64. Run it through EXIF Remover first if those should not travel.
Can I turn a Base64 string back into an image here?
Yes. Switch the action to Decode, paste the string or a whole data: URL, and press Process. A data: URL brings its own type; for a bare string the page reads the type from the first bytes, and the extension menu is the fallback. Base64 to Image is a page made just for that direction.
Is there a .txt download of the result?
Not in File mode: the result offers Copy to Clipboard only. The Download as .txt button belongs to Text mode, which encodes typed text rather than files.
Why does my PNG come out as data:image/jpeg?
The prefix follows the file name, not the bytes. In our test PNG bytes saved as png-named.jpg became data:image/jpeg;base64,... in the four browser engines we tried. Pasting that string into the Decode side brought the warning The data URL says image/jpeg, but the bytes are a PNG image, and the file was saved as .png. Renaming the file before encoding gives the right prefix.
Does the Base64 string have line breaks in it?
No. None of the test strings had a line break, including one of 35,176,400 characters. If a system wants the text wrapped into lines, the wrapping has to happen there.
How large an image can I convert?
The page sets no size limit of its own. A 26.38 MB file appeared as a 35,176,400-character string in 4.0 to 7.5 seconds in three of the four browser engines we tried, while the WebKit build took 13.4 seconds for a 10.55 MB file and about 2.2 minutes for the 26.38 MB one.
How can I check that the string turns back into the same image?
Switch the action to Decode in the same tool and paste the string: the result names the type it read from the first bytes, and the file can be downloaded. Every decoded test file that finished had the same SHA-256 as its original; in the WebKit build the decode of the 26.38 MB file had not finished when the test stopped.