Home / Free tools / Images / Image to Base64 Converter
Image to Base64 Converter
Choose a picture to get its Base64 text as a data URI, CSS, HTML or Markdown, or paste Base64 to get the image back. Nothing is uploaded.
Drag and drop an image here, or
Base64 back to an image
Runs in your browser. Nothing you paste or choose is uploaded or stored.
What this image to Base64 converter does
This tool turns a picture into a Base64 text string, and a Base64 string back into a picture. Choose an image and you get the text in the form you need: a full data URI, the bare Base64, a CSS background-image rule, an HTML img tag or a Markdown image. The preview, the size change and the conversion all happen in your browser, so the picture is not uploaded. In the lower box you can paste Base64 or a data URI and get the image back, with a download link.
A data URI places the file inside the text of a page instead of linking to it. Instead of <img src="logo.png">, the page contains <img src="data:image/png;base64,iVBORw0KGgo..."> and the browser needs no extra request to show it.
How it works
- The file type is detected from the content, not the name. The tool reads the first bytes, the "magic number", to tell PNG, JPEG, GIF, WebP, BMP, ICO, AVIF and SVG apart, and warns if the file is not an image at all.
- The bytes are encoded with Base64, as in the Base64 encoder. Three bytes become four characters, so the text is about 33% larger than the file.
- The pieces are assembled into the output you chose, with the right type in the prefix. The alt text of the HTML and Markdown outputs is taken from the file name.
- Decoding accepts a data URI, a bare string, line breaks and missing padding, checks that the decoded bytes are an image and shows it.
- Limit. Pictures up to 5 MB are accepted, because the text of a larger one would be too big to be useful.
Worked example
Take a PNG icon of 300 bytes. Base64 turns it into 400 characters, a rise of 33.3%, and the data URI adds the 22 characters of data:image/png;base64,. The CSS output is background-image: url("data:image/png;base64,..."); and the HTML output is an img tag with the same URI in its src attribute. The tool shows these numbers for your own file in the green message above the result: type, original bytes, characters produced and the percentage increase. The tests for this page convert real PNG, JPEG and WebP files to Base64 and back and check that the bytes are identical.
When inlining helps, and when it hurts
- It helps for very small images, such as an icon of a few hundred bytes to about 10 KB, because it saves a network request. It is also useful in a single HTML file that must work on its own, or in an HTML email template for a system that allows it.
- It hurts for larger pictures. The text is a third bigger than the file, it cannot be cached separately from the page that holds it, and it slows the first display. The tool warns when a file is over 100 KB. For photos, compress and resize them instead with the image compressor and the image resizer, and link to the file.
- Email is unreliable. Several mail programs, including Gmail on the web, do not show images given as data URIs. Attach or host the image for email.
- SVG can be used as plain text. A short SVG does not always need Base64; it can sit in a data URI as URL-encoded text, which is smaller. The URL encoder makes that conversion.
Tips
Convert the format first if the file is large: a PNG photo is often several times bigger than the same photo as a WebP, which you can make with the image converter. If the text will be placed inside a CSS file, remember that the quotes around the URL matter, and that the whole string must stay on one line. A Base64 string that begins with iVBORw0KGgo is a PNG, one that begins with /9j/ is a JPEG, one that begins with R0lGOD is a GIF and one that begins with UklGR is a WebP, which helps you recognise a string you find in code.
Privacy
Your image is read and converted on your own device. It is not uploaded, stored or logged, and the Base64 text is not added to the page address. Decoded pictures are shown from a temporary address that exists only in your browser. More image utilities are listed on the Image tools page.
Questions
What is a data URI?
A data URI holds the content of a file inside the address itself, in the form data:type;base64,text. A browser can show an image from it without fetching another file.
Why is the Base64 text bigger than my image?
Base64 turns every three bytes into four characters, so the text is about 33% larger than the file, plus a few characters for the prefix.
How big an image should I convert?
Inlining makes sense for small images, up to roughly 10 KB. Over 100 KB the tool shows a warning, because the page that holds the text gets slower and the picture cannot be cached separately.
Can I turn Base64 back into an image?
Yes. Paste it, or a full data URI, in the second box. The tool checks that it is an image, shows it and offers a download with the right file extension.
Which image types are supported?
PNG, JPEG, GIF, WebP, BMP, ICO, AVIF and SVG are recognised from their content. Any type your browser can display can be previewed.
Does it work for images in email?
Often not. Many email programs block data URIs, so attach the image or link to a hosted copy for email.
Is my image uploaded?
No. The file is read in your browser and converted there. It is never sent to a server.
Google, Merchant Center, YouTube, LinkedIn, Indeed, Glassdoor and Shopify are trademarks of their owners. Van Born Labs is independent and not affiliated with them. Google's own help pages are the final word on its rules.