🖼️ Image to Base64 Converter
By ToolNimba Web Dev Team · Updated 2026-06-19
PNG, JPG, GIF, WebP, SVG, BMP or ICO. The file is read in your browser and never leaves your device.
Choose an image file to generate its Base64 data URI.
This tool turns an image into a Base64 data URI: a single long text string you can paste straight into HTML or CSS, with no separate image file to host. Choose a PNG, JPG, GIF, WebP, SVG, BMP or ICO file and you instantly get the data:… string, plus a ready-to-paste <img> tag and a CSS background snippet. The image is read in your browser and is never uploaded to any server, so even private graphics stay on your device.
What is the Image to Base64?
Base64 is a way of writing binary data (like the bytes of an image) using only 64 plain text characters: A to Z, a to z, 0 to 9, plus + and /. Because the result is ordinary text, it can live anywhere text is allowed, including inside an HTML or CSS file. A data URI wraps that text in a small header so a browser knows what it is decoding. The format is data:[media type];base64,[the Base64 text], for example data:image/png;base64,iVBORw0KGgo… The browser reads the media type, decodes the Base64 back into the original bytes, and draws the image, exactly as if it had downloaded a separate file.
The main reason to embed an image this way is to avoid a separate network request. A normal <img src="logo.png"> makes the browser fetch logo.png as its own download. A small icon, spinner or background pattern embedded as a data URI travels inside the HTML or CSS that already loaded, so there is one less round trip. This can speed up the first paint for tiny, critical images, and it is handy for self-contained files such as email templates, single-file HTML pages, bookmarklets and offline demos where you cannot rely on external assets being present.
The trade-off is size. Base64 represents every 3 bytes of the original using 4 text characters, so the encoded string is about 33% to 37% larger than the file once you add the data URI header and any padding. Embedded images also cannot be cached separately by the browser: the same icon repeated across ten pages is downloaded ten times instead of once. For these reasons Base64 embedding suits small images (rules of thumb often cap it around a few kilobytes); large photos are almost always better left as normal linked files.
When to use it
- Embedding a small logo, icon or spinner directly in an HTML email so it shows without an external image host.
- Inlining a tiny background pattern or icon in CSS to remove an extra HTTP request and speed up first paint.
- Building a single self-contained HTML file (a demo, report or offline page) that carries its images inside it.
- Pasting an image into a JSON payload, a JavaScript string, or a Markdown file that does not support file attachments.
- Quickly inspecting or sharing an image as text when you cannot attach a binary file.
How to use the Image to Base64
- Click Choose an image and pick a PNG, JPG, GIF, WebP, SVG, BMP or ICO file from your device.
- Wait a moment while the file is read in your browser (nothing is uploaded).
- Copy the Base64 data URI from the first box, or copy the ready-made <img> tag or CSS background snippet.
- Paste the snippet into your HTML, CSS, email template or other file.
Formula & method
Worked examples
You have a 1,024 byte (1 KB) PNG icon and want to know how long its data URI will be.
- Base64 characters = ceil(1024 ÷ 3) × 4 = 342 × 4 = 1,368
- Add the header "data:image/png;base64," which is 22 characters
- Total length = 1,368 + 22 = 1,390 characters
- Growth = (1,390 − 1,024) ÷ 1,024 = 0.357
Result: The data URI is about 1,390 characters, roughly 36% larger than the 1 KB file.
You want the data URI for a 1-pixel transparent GIF (a classic 43 byte spacer image).
- Base64 characters = ceil(43 ÷ 3) × 4 = 15 × 4 = 60 (the 43 bytes become "R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
- Prefix with the header "data:image/gif;base64,"
- Combine into a single string
Result: data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==
Common image media types used in the data URI header
| Image format | Media type in the data URI |
|---|---|
| PNG | data:image/png;base64,… |
| JPEG / JPG | data:image/jpeg;base64,… |
| GIF | data:image/gif;base64,… |
| WebP | data:image/webp;base64,… |
| SVG | data:image/svg+xml;base64,… |
| ICO | data:image/x-icon;base64,… |
Roughly how Base64 grows a file (data URI header not included)
| Original file size | Approx. Base64 characters | Approx. increase |
|---|---|---|
| 100 bytes | 136 | about 36% |
| 1 KB (1,024 bytes) | 1,368 | about 34% |
| 10 KB | 13,656 | about 33% |
| 100 KB | 136,536 | about 33% |
Common mistakes to avoid
- Embedding large photos as Base64. A data URI is about a third larger than the file and cannot be cached separately, so inlining a big photo bloats your HTML or CSS and is downloaded fresh on every page. Keep embedding for small images (a few kilobytes) and link large ones normally.
- Forgetting the data: prefix when pasting. The raw Base64 string on its own is not enough. Browsers only render it when it begins with the full data:image/…;base64, header. Copy the whole data URI box, not just the characters after the comma.
- Adding line breaks inside the string. A data URI must be one continuous string. If your editor wraps or inserts newlines into the value of src or url(), the image may fail to load. Keep it on a single line.
- Using the wrong media type. If you relabel a JPEG as image/png, some browsers still cope but others refuse to render it. The media type should match the actual format; this tool sets it from the file you choose.
Glossary
- Base64
- An encoding that represents binary data using 64 text characters (A–Z, a–z, 0–9, + and /), so binary can be stored or transmitted as plain text.
- Data URI
- A URL beginning with data: that contains the file content inline, in the form data:<media-type>;base64,<data>, instead of pointing to a separate file.
- Media type (MIME type)
- A label such as image/png or image/svg+xml that tells the browser what kind of data follows so it can decode and display it correctly.
- Padding
- One or two = characters added to the end of a Base64 string so its length is a multiple of four.
- FileReader
- A browser API that reads a chosen file into memory, here as a Base64 data URL, entirely on your device.
Frequently asked questions
How do I convert an image to Base64?
Choose your image file in the tool above and it instantly produces the Base64 data URI in your browser. You can then copy the data:… string, or use the ready-made <img> tag or CSS background snippet. No upload or sign-up is needed.
Is my image uploaded to a server?
No. The image is read locally using your browser FileReader API and encoded on your own device. Nothing is sent over the network, which makes this safe for private or confidential graphics.
What is a data URI?
A data URI is a string that carries a file inline instead of linking to it. It has the form data:<media-type>;base64,<data>, for example data:image/png;base64,iVBORw0KGgo… A browser decodes it back into the original image and displays it as if it had loaded a separate file.
Why is the Base64 string larger than my image file?
Base64 represents every 3 bytes of the original as 4 text characters, so the encoded data is about 33% to 37% larger than the file once the data URI header and any padding are included. That size overhead is the main reason to embed only small images.
When should I embed an image as Base64 instead of linking it?
Embedding works best for small, critical images (icons, spinners, tiny backgrounds) and for self-contained files like HTML emails or single-file pages. For large photos or images reused across many pages, a normal linked file is faster because it downloads once and can be cached.
Which image formats are supported?
Any image your browser can read, including PNG, JPG, GIF, WebP, SVG, BMP and ICO. The tool detects the format and writes the correct media type (such as image/png or image/svg+xml) into the data URI header automatically.