ToolNimba

🖼️ Image to Base64 Converter

Shihab Mia By Shihab Mia · Updated 2026-07-31

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.

Browsers do technically allow very long data URIs. Chromium-based browsers and Firefox now handle data URLs up to hundreds of megabytes, and Safari (WebKit) allows over a gigabyte, so a modern browser will not usually refuse to render a large embedded image outright. That is different from it being a good idea: a multi-megabyte data URI still bloats your HTML or CSS file, slows down parsing, and cannot be lazy-loaded or cached the way a linked file can, so the practical ceiling for "worth embedding" is far lower than the technical one, generally a few kilobytes to a few tens of kilobytes.

Developers also generate Base64 image strings outside the browser. In Python, base64.b64encode(open("file.png", "rb").read()) turns the raw bytes into the same text this tool produces. In Node.js, Buffer.from(fs.readFileSync("file.png")).toString("base64") does the equivalent, and in browser JavaScript the FileReader API (readAsDataURL) is what powers tools like this one. This matters for build pipelines that inline critical icons at compile time, for APIs that accept an image as a JSON string field, and for CSS-in-JS tooling that embeds small assets automatically.

One detail that trips people up: a data URI embedded in HTML or CSS is subject to the Content-Security-Policy of the page. If a site sets a strict img-src directive without the data: keyword, browsers will silently block the embedded image even though the markup looks correct. Screen readers and accessibility tooling also cannot infer meaning from the Base64 text itself, so an <img> built from a data URI still needs a normal, descriptive alt attribute just like any other image.

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.
  • Storing a small thumbnail directly in a database field or API response instead of managing a separate file and URL.
  • Quickly inspecting or sharing an image as text when you cannot attach a binary file.

How to use the Image to Base64

  1. Click Choose an image and pick a PNG, JPG, GIF, WebP, SVG, BMP or ICO file from your device.
  2. Wait a moment while the file is read in your browser (nothing is uploaded).
  3. Copy the Base64 data URI from the first box, or copy the ready-made <img> tag or CSS background snippet.
  4. Paste the snippet into your HTML, CSS, email template or other file.
  5. Need to go the other way? Use a Base64 to Image tool to decode a data URI back into a downloadable file.

Formula & method

A data URI has the form data:<media-type>;base64,<data>. The Base64 portion encodes every 3 bytes as 4 characters, so its length is roughly ceil(bytes ÷ 3) × 4, making the string about 33% to 37% larger than the original file.
Image file(binary bytes)Base64 encode(FileReader API)data: URIready to pasteEvery 3 bytes of the file become 4 Base64 charactersBBB3 bytescccc4 charactersResult: the encoded text is about 33% to 37% larger than the original file

Worked examples

You have a 1,024 byte (1 KB) PNG icon and want to know how long its data URI will be.

  1. Base64 characters = ceil(1024 ÷ 3) × 4 = 342 × 4 = 1,368
  2. Add the header "data:image/png;base64," which is 22 characters
  3. Total length = 1,368 + 22 = 1,390 characters
  4. 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).

  1. Base64 characters = ceil(43 ÷ 3) × 4 = 15 × 4 = 60 (the 43 bytes become "R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
  2. Prefix with the header "data:image/gif;base64,"
  3. Combine into a single string

Result: data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==

You want a small icon.png to appear as a CSS background instead of linking a separate file.

  1. Upload icon.png to the tool and copy the data URI it produces
  2. Write the CSS rule: .icon { background-image: url("data:image/png;base64,...."); }
  3. Add background-repeat: no-repeat and background-size to control how it displays

Result: The icon renders directly from the stylesheet, with no extra HTTP request and no separate file to host.

Common image media types used in the data URI header

Image formatMedia type in the data URI
PNGdata:image/png;base64,…
JPEG / JPGdata:image/jpeg;base64,…
GIFdata:image/gif;base64,…
WebPdata:image/webp;base64,…
SVGdata:image/svg+xml;base64,…
ICOdata:image/x-icon;base64,…

Roughly how Base64 grows a file (data URI header not included)

Original file sizeApprox. Base64 charactersApprox. increase
100 bytes136about 36%
1 KB (1,024 bytes)1,368about 34%
10 KB13,656about 33%
100 KB136,536about 33%

Data URI size limits by browser, and the practical limit to actually aim for

Browser / eraTechnical data URI limitWhat that means in practice
Chrome / Edge (Chromium)About 512 MBWill render huge data URIs, but they still bloat and slow down the page
Firefox (modern versions)About 512 MBOlder Firefox versions capped this much lower (as low as 256 KB)
Safari (WebKit)About 2 GBHighest technical ceiling of the major browsers
Internet Explorer 832 KB hard limitLegacy constraint, rarely relevant today
Recommended practical limitA few KB to a few tens of KBBeyond this, a normal linked file almost always performs better

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.
  • Dropping the alt attribute. A Base64 string carries no meaning for screen readers. An <img> built from a data URI still needs a normal, descriptive alt attribute; skipping it hurts accessibility exactly as much as skipping alt text on a linked image.
  • Blocking data: URIs with a strict Content-Security-Policy. If a page sets a CSP img-src directive without the data: keyword, browsers silently refuse to render embedded images even though the HTML looks correct. Add data: to img-src (and style-src if used in CSS) when you rely on inline images.

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.
Byte
The basic unit of binary data, 8 bits. Base64 groups bytes in sets of 3 and turns each group into 4 text characters, which is the source of the 33% size increase.
Content Security Policy (CSP)
A browser security header that can restrict where images, scripts and styles may load from; it must include data: in img-src for embedded Base64 images to render.
Base64url
A URL-safe variant of Base64 that replaces + and / with - and _ and often drops padding, used in things like JWTs and URL query parameters rather than in image data URIs.

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.

Is there a maximum size for a Base64 image?

Modern browsers technically allow data URIs of hundreds of megabytes or more, so there is no hard block on large images. In practice, a data URI stops being worth it well before that: a few kilobytes to a few tens of kilobytes is a sensible ceiling, beyond which a normal linked file loads and caches better.

Does using Base64 images hurt page speed or SEO?

It can. Embedding many or large images bloats the HTML or CSS file, delays parsing, and prevents the browser from caching those images separately, which can slow down repeat visits and hurt metrics like Largest Contentful Paint. Reserve Base64 embedding for small, above-the-fold icons rather than photos or images used on many pages.

How do I convert an image to Base64 in Python or JavaScript?

In Python, base64.b64encode(open("file.png", "rb").read()) encodes the file bytes. In Node.js, Buffer.from(fs.readFileSync("file.png")).toString("base64") does the same. In browser JavaScript, the FileReader API method readAsDataURL() produces the full data URI directly, which is what powers this tool.

Can I convert a Base64 string back into an image file?

Yes. Paste the Base64 text or data URI into a Base64 to Image decoder to reconstruct the original file and download it. The process simply reverses this tool: it decodes the text back into bytes and lets you save them with the correct file extension.