Skip to main content
IT

Image to Base64

Convert an image into a Base64-encoded string — full data URI or raw Base64, character count, one-click copy, all done locally.

Did you like the tool? Thanks!
Share:

More Image Tools Tools

IC

Image Cropper

Crop any image to exactly the area you need, with a live preview — nothing is uploaded, everything happens in your browser.

IR

Image Resizer

Resize any image to an exact width and height in your browser — optional aspect-ratio lock, PNG/JPEG/WebP output, nothing uploaded.

IC

Image Compressor

Shrink an image's file size by re-encoding it at a chosen quality level — live before/after size comparison, JPEG/WebP/PNG output, done locally.

IF

Image Flip & Rotate

Flip an image horizontally or vertically and rotate it by any angle — quick 90/180/270° buttons or a free-angle slider, corners never clipped.

BT

Base64 to Image

Paste a Base64 string or data URI and preview the decoded image instantly — auto-trims whitespace, lets you pick the assumed format, download in one click.

PI

Placeholder Image Generator

Generate a simple placeholder image for wireframes and mockups — custom size, colors and text, auto-sized to fit, PNG/JPEG/WebP output.

IF

Image Format Converter

Convert an image between PNG, JPEG, WebP and BMP entirely in your browser — no upload, instant preview, adjustable quality.

FG

Favicon Generator

Turn any image into a complete favicon package — six PNG sizes plus a combined multi-resolution .ico file, generated locally in your browser.

AA

ASCII Art Generator

Turn a photo into text-based ASCII art, or type a short message as a large block-letter banner — both rendered entirely in your browser.

QC

QR Code Generator

Generate a real, scannable QR code from text, a URL, Wi-Fi details, an email address or a phone number — encoded entirely in your browser, no external API.

Reading file…

characters
Preview of the uploaded image

How to Use Image to Base64

Choose an image file and it's immediately converted to a Base64 string. Use the two tabs to switch between the full data URI (ready to paste directly into an <img src="..."> attribute or a CSS background-image) and the raw Base64 text with no data: prefix (for contexts that expect just the encoded bytes). The character count updates with whichever view is showing, and the copy button grabs exactly that text with a visible "Copied!" confirmation.

About Image to Base64

Base64 is a way of representing arbitrary binary data — like the bytes that make up a JPEG or PNG file — using only 64 printable, plain-text characters (A-Z, a-z, 0-9, plus two extra symbols, typically + and /). It exists because many systems and formats were built to carry text safely but not raw binary bytes: email, older configuration file formats, JSON, CSS, and HTML attributes can all reliably contain a Base64 string, whereas embedding raw binary bytes directly into those same contexts risks corruption, encoding mismatches, or outright breaking the surrounding format. Base64 solves this by mapping every 3 bytes of binary input to exactly 4 text characters, so any binary payload — including an entire image file — can be represented as a plain string that safely survives being copied, pasted, stored in a database text column, or embedded directly inside another text-based file. The most common practical use for a Base64-encoded image on the web is embedding it directly inside HTML or CSS without a separate file request: an `<img src="data:image/png;base64,iVBORw0KG...">` tag or a CSS `background-image: url(data:image/png;base64,...)` declaration renders the image immediately from the encoded text itself, with no additional network round-trip needed to fetch a separate image file. This is genuinely useful for very small images — icons, tiny logos, a handful of UI decorations — where the overhead of a separate HTTP request would outweigh the benefit, or for contexts where a single self-contained file (an email, a generated PDF, an offline document) needs to include an image without any external dependency at all. It comes with a real trade-off, though: because of that 3-bytes-to-4-characters expansion, a Base64-encoded image is always roughly 33% larger than the original binary file, and unlike a normal image file referenced by URL, an embedded data URI can never be cached separately by the browser — it's re-downloaded and re-parsed every single time the surrounding HTML or CSS document loads, however large it is. For anything beyond a small icon, a normal image file reference almost always performs better. The distinction between the full data URI and the raw Base64 string matters because different contexts expect different things. The full `data:image/png;base64,...` form is what browsers, `<img>` tags, and CSS expect directly — the `data:image/<type>;base64,` prefix tells the parser exactly how to interpret the text that follows. Plenty of other contexts, though — a database column storing just the encoded bytes, an API that reconstructs the data URI itself from a separate stored MIME type, or a backend language's own Base64-decoding function — expect only the raw encoded string with no prefix at all, and would either fail to decode correctly or store an unwanted extra prefix if handed the full data URI by mistake. Having both readily available side by side removes the need to manually strip or reconstruct the prefix by hand. Everything in this tool happens using the browser's built-in `FileReader.readAsDataURL()` method, which reads the file you choose and produces the full data URI directly — no image data is ever transmitted to a server in the process.

Details & Tips

How the conversion works: when you choose a file, it's read using `FileReader.readAsDataURL(file)`, a standard browser API that reads the file's raw bytes and returns them already encoded as a complete data URI string in the form `data:<mime-type>;base64,<encoded-data>` — the browser handles both the MIME-type detection and the Base64 encoding itself; no custom encoding logic is needed or used. The "Full data URI" view displays that string exactly as returned. The "Raw Base64" view is derived by taking everything after the first comma in that string (`dataUri.slice(dataUri.indexOf(',') + 1)`), which strips the `data:image/png;base64,` (or equivalent) prefix and leaves only the encoded bytes. The character count shown always reflects whichever of the two views is currently selected, recalculated as `displayedString.length` — since the full data URI view includes the `data:image/<type>;base64,` prefix (typically 20-30 extra characters depending on the MIME type), its count will always be slightly higher than the raw view's count for the same underlying image. Worked size example: because Base64 encodes every 3 bytes as 4 characters, the encoded text is always close to 4/3 (about 133%) the size of the original binary file, plus the small fixed overhead of the data: prefix. A 150KB JPEG photo, for instance, produces a raw Base64 string of roughly 200KB of text — around 200,000 characters — which is large enough that some code editors, browser dev tools, or older systems can become noticeably slower to render or scroll through a file containing it. This is exactly why the tool shows an inline warning (not a blocking error) for any source file over roughly 2MB: at that size the resulting text comfortably exceeds 2.6 million characters, which is still perfectly valid and functional, but worth knowing about before you paste it somewhere that might struggle with a text block that large. The copy button copies exactly the string currently displayed — full data URI or raw Base64, whichever tab is active — using the browser's `navigator.clipboard.writeText()` API. On a successful copy, the button label switches to "Copied!" for two seconds before reverting, giving a clear, unambiguous confirmation that the copy succeeded rather than leaving you to guess. A small preview thumbnail of the uploaded image is also shown alongside the copy button, generated by setting the same data URI directly as an `<img>` element's `src` — this doubles as an implicit sanity check that the encoding round-trips correctly, since if the data URI were somehow malformed, the thumbnail itself would fail to render.

Frequently Asked Questions

What's the difference between "Full data URI" and "Raw Base64"?
The full data URI includes the data:image/<type>;base64, prefix and is what you paste directly into an <img src="..."> or CSS background-image. Raw Base64 is everything after that prefix — the encoded bytes only — for contexts like a database column or an API that expects just the encoded data.
Why is the Base64 string so much larger than my original file?
Base64 encodes every 3 bytes of binary data as 4 text characters, so the encoded text is always roughly 4/3 (about 133%) the size of the original file, plus a small fixed amount for the data: prefix if you're using the full data URI.
Why did I get a warning about a large file?
Files over roughly 2MB produce a Base64 string of a few million characters, which is still completely valid but can be slow to copy, scroll through, or render in some code editors or older systems — the warning is informational, not an error, and doesn't block the conversion.
How do I use the full data URI in my HTML?
Paste it directly as the src attribute of an <img> tag: <img src="data:image/png;base64,...">, or inside a CSS background-image: url(...) declaration. The browser renders it immediately with no separate image request.
Is embedding an image as Base64 always a good idea?
It's best suited to very small images like icons or tiny logos. Beyond that, the ~33% size overhead and the fact that a data URI can't be cached separately by the browser (it re-downloads with every page load) usually make a normal linked image file the better choice.
Is my image uploaded to convert it?
No. The conversion uses the browser's built-in FileReader.readAsDataURL() method, which reads and encodes the file entirely on your device. Nothing is transmitted to a server at any point.
What does the character count actually measure?
The exact length (in characters) of whichever view — full data URI or raw Base64 — is currently selected. Since the full view includes the data: prefix, its count is always slightly higher than the raw view's count for the same image.
How do I know the copy actually worked?
The copy button's label changes to "Copied!" for two seconds immediately after a successful clipboard write, then reverts to its normal label — a clear visual confirmation rather than a silent action.
Can I convert any image format?
Any file the browser reports as an image/* MIME type can be converted — JPEG, PNG, WebP, GIF and others are all supported. Non-image files show an inline error immediately instead of being processed.
Does the preview thumbnail prove the encoding worked correctly?
Effectively, yes — the thumbnail is rendered directly from the same data URI shown in the textarea, so if it displays correctly, the encoding round-trips properly and the string is safe to use elsewhere.

Part of These Collections

Also Available As

image to base64, convert image to base64, base64 encode image, image to data uri, base64 image string generator

Found a Problem?

Let us know if something with Image to Base64 isn't working as expected.

Thanks — we'll take a look.