Drop images to encode to Base64
JPG · PNG · WebP · AVIF · GIF · SVG · BMP · ICO — or paste from your clipboard. Nothing is uploaded.
Loading…
JPG · PNG · WebP · AVIF · GIF · SVG · BMP · ICO — or paste from your clipboard. Nothing is uploaded.
Convert images to Base64 strings, Data URIs, HTML, CSS, Markdown and JSON — and decode Base64 back to real image files — without uploading a single byte. Optimise before encoding, analyse web-performance impact, validate strings, generate code for fifteen stacks and export entire batches. Everything runs locally on your device.
Bytes are read with the File and ArrayBuffer APIs and encoded on your device — no server round-trip, no fake demo output.
Raw Base64, Data URI, HTML <img>, CSS background, Markdown and a JSON object — copy the exact shape your code needs.
Paste a Base64 string or Data URI, or upload a TXT/JSON file, and get a real downloadable PNG, JPG, WebP, GIF or SVG back.
Resize, compress, convert to WebP/AVIF and strip metadata first so the Base64 string is as small as possible.
See the encoding overhead, gzip estimate and a verdict on whether the asset is small enough to inline.
Ready-to-paste encode, decode and render snippets for JavaScript, TypeScript, React, Vue, Node, Python, PHP, Go, Rust and more.
Detect invalid characters, missing padding, wrong MIME types and corruption — with one-click repair suggestions.
Encode many images at once and export everything as TXT, JSON, CSV or a single ZIP archive.
Drag and drop, browse, paste from the clipboard, import a folder or paste an image URL. JPG, PNG, WebP, AVIF, GIF, SVG, BMP, ICO and more are supported.
Pick raw Base64, a Data URI, an HTML <img> tag, a CSS background rule, Markdown or a JSON object. Optionally optimise (resize, compress, convert) first.
Copy the result with one click, or download it as TXT, JSON, CSV or a ZIP. Use the generated snippets for your language of choice.
Base64 is a binary-to-text encoding scheme that represents arbitrary binary data — like the bytes of a JPG or PNG — using a 64-character alphabet of letters, digits and two symbols (A–Z, a–z, 0–9, plus + and /). It was designed so that binary content could travel safely through systems that were built for plain text, such as email bodies, JSON payloads, HTML attributes and URLs, without being corrupted by characters those systems treat specially.
The encoder works in groups of three bytes (24 bits) and splits them into four 6-bit chunks, mapping each chunk to one character of the alphabet. Because four output characters represent three input bytes, Base64 is always about 33% larger than the original binary — three bytes become four characters. When the input length is not a multiple of three, one or two padding "=" characters are appended so the output stays a multiple of four. This is why almost every Base64 string ends in "=", "==" or nothing at all.
For images specifically, Base64 lets you embed the entire picture directly inside your code as text. Instead of the browser making a separate network request for logo.png, the bytes of the logo live inside your HTML, CSS or JavaScript as a string. That string is decoded back into the exact same image by the browser — Base64 is lossless, so the decoded bytes are byte-for-byte identical to what you encoded.
When you add an image to this converter, your browser reads the raw file bytes locally using the File and ArrayBuffer APIs — the file never leaves your device. Those bytes are then passed through a Base64 encoder that produces the text string, and the tool prepends a Data URI header (for example data:image/png;base64,) so browsers and CSS know how to interpret it. The whole pipeline runs in JavaScript on your machine.
A Data URI has three parts: the scheme and MIME type (data:image/png), the encoding marker (;base64), and the payload itself (the long Base64 string after the comma). The MIME type tells the consumer what kind of image it is; getting it wrong is the most common reason an otherwise-valid Base64 image refuses to render. This tool detects the correct MIME from the file’s magic bytes, so the header always matches the payload.
If you enable the optimise options, the image is first decoded onto an HTML canvas where it can be resized, re-compressed, converted to a more efficient format such as WebP or AVIF, and re-encoded — which also strips all EXIF and GPS metadata. Only then is it turned into Base64. Because Base64 multiplies every byte by roughly 1.33, shrinking the source first has an outsized effect on the final string length.
A normal image on the web is a binary file served over HTTP: the browser requests cat.jpg, the server streams the bytes, and the browser caches the file so it does not have to download it again. Base64 takes a different trade-off — the image is no longer a separate file but text embedded inside another file. This removes the extra HTTP request entirely, which can be a real win for tiny, critical assets, but it comes with costs.
The first cost is size: Base64 is ~33% larger than the binary it represents. The second is caching — an inlined image cannot be cached on its own, so every page or stylesheet that contains it re-downloads those bytes on every load, and updating the image means busting the cache of the whole document. The third is parsing: a large Base64 string sitting inside your HTML or CSS blocks the parser until the entire string has been received.
The practical rule that emerges is simple: inline small, frequently-reused, render-critical assets (icons, tiny logos, 1×1 spacer or tracking pixels, decorative gradients) as Base64, and keep everything else as cached binary files referenced by URL. This converter’s performance analyzer applies exactly this logic and gives each image a verdict so you do not have to guess.
A Data URI (also called a data URL) is defined by RFC 2397 and lets you put a resource’s contents directly inside a URL. The format is data:[<media type>][;base64],<data>. For images you will almost always see the base64 variant, for example data:image/svg+xml;base64,PHN2Zy4uLg== or data:image/png;base64,iVBORw0KGgo… — anywhere a browser accepts a URL (the src of an img, the url() of a CSS background, the href of a link rel="icon"), it will accept a Data URI.
Not every Data URI uses Base64. Text-based formats like SVG are frequently percent-encoded instead, which keeps them human-readable and can even be slightly smaller than Base64 for small SVGs. This tool understands both: when you decode a percent-encoded SVG Data URI it is handled correctly, and the validator flags whether a string is base64 or percent-encoded so you know how to transport it.
Data URIs are supported in every modern browser, in most email clients (with notable exceptions — Gmail strips them from img tags), and across iOS and Android webviews. They are the cleanest way to ship a self-contained asset that has no external dependencies, which is why they are popular for email templates, single-file HTML exports, browser extensions and offline-first apps.
In front-end work, Base64 Data URIs shine for the handful of assets that are small and needed immediately. Inlining a 1 KB SVG icon into your critical CSS removes a request from the longest pole in your page-load waterfall. Build tools such as webpack, Vite and Next.js do this automatically below a size threshold (commonly 4–8 KB) precisely because that is where inlining pays off.
Base64 is also the backbone of low-quality image placeholders (LQIP) and blur-up techniques: a tiny, heavily-compressed version of an image is inlined as a Data URI and shown instantly while the full-resolution file loads. Next.js uses exactly this pattern for its blurDataURL prop. Generating that placeholder is a perfect job for this tool — optimise the image down to a few hundred bytes, then copy the Data URI.
Where Base64 hurts is large hero images, photo galleries and anything reused across pages. Because inlined bytes are duplicated into every document and bypass the browser cache, a 200 KB photo encoded into your CSS becomes a ~270 KB string downloaded on every visit. For those, keep the file external and let HTTP caching, CDNs and modern formats do their job.
JSON has no native binary type, so when an API needs to carry an image inside a JSON body, the conventional solution is to Base64-encode the bytes into a string field. This is how many upload endpoints, webhooks, serverless functions and AI/vision APIs accept images — you POST a JSON object with a data field containing the Base64 (sometimes the full Data URI, sometimes just the raw payload).
A frequent integration bug is mixing up the two shapes. Some APIs want the bare Base64 (iVBORw0KGgo…) while others expect a complete Data URI (data:image/png;base64,iVBORw0KGgo…). Sending the wrong one results in a corrupted image or a 400 error. This converter gives you both, clearly labelled, plus copy-paste REST (fetch and curl) and GraphQL examples so the field is populated correctly.
Base64 is also used outside JSON: in HTTP Basic auth headers, JWT segments, data attributes, and multipart fallbacks. The same encoding rules apply everywhere, which is why a single, correct Base64 string from a trustworthy encoder saves debugging time across every one of those contexts.
The headline number — Base64 is 33% larger — is true on the wire only if you ignore compression. Base64 text compresses very well under gzip and brotli because it draws from a small alphabet, so the real transfer penalty over a compressed connection is usually much smaller than 33%; for already-compressed images it often lands in the 0–15% range. The performance analyzer in this tool estimates the gzipped size so you can reason about real-world cost, not the worst case.
The more important performance factor is caching and parsing, not raw size. An external image is fetched in parallel, cached, and reused; an inlined image is parsed inline, re-sent on every load, and invalidates its host document when it changes. For a 2 KB icon those downsides are negligible and the saved request wins. For a 100 KB illustration they dominate and inlining is a net loss. Size thresholds (roughly: great under 6 KB, acceptable under 40 KB, risky above) are a reliable heuristic.
There is also a memory and CPU angle. Decoding a very large Base64 string allocates the full binary plus the text in memory, and doing it on the main thread can cause jank. For batch or very large work, encode/decode off the main thread (a Web Worker) and avoid holding many giant Data URIs in the DOM at once. This tool processes files locally and releases object URLs when you are done to keep memory in check.
Because Base64 amplifies every byte, the single most effective thing you can do is shrink the source image before encoding. Three levers matter most: dimensions, format and quality. Resizing a 4000-pixel photo down to the size it actually renders can cut the byte count by 90% before Base64 even runs; that 90% saving carries straight through to the final string.
Format choice is the next lever. An opaque PNG is almost always larger than the same image as a quality-75 JPEG or a WebP; transparency-bearing images compress best as WebP or AVIF. This tool can convert to JPEG, PNG, WebP or AVIF on the canvas before encoding, and the act of re-encoding also discards EXIF, GPS coordinates and other metadata — a privacy win as well as a size win.
Quality is the fine-tuning lever for lossy formats. Dropping JPEG/WebP quality from 92% to 75% typically removes a large fraction of the bytes with little perceptible difference, especially for thumbnails and placeholders that will be displayed small. Combine all three — resize, convert, compress — and a multi-megabyte photo becomes a few-kilobyte Data URI suitable for inlining.
Encoding an image to Base64 does not encrypt it. Base64 is reversible by anyone — it is encoding, not encryption — so never treat a Base64 string as a way to hide sensitive content. Conversely, because re-encoding through a canvas strips metadata, optimising an image here is a genuine privacy improvement: GPS coordinates and camera details embedded by phones are removed before the Base64 is produced.
This converter is privacy-first by construction: every byte is read and encoded in your browser with no upload, so there is no server log, no temporary file on someone else’s disk, and nothing to leak. That matters when the images are screenshots, documents, identity photos or anything confidential. It also means the tool works offline once the page has loaded.
On the consuming side, be careful when decoding untrusted Base64. A malicious string could declare an image MIME type but contain a different payload, or be an SVG with embedded scripts. Validate the MIME against the magic bytes (this tool does), sanitise SVG before rendering it inline, and apply a Content-Security-Policy that constrains data: URIs to the contexts where you actually need them.
Use Base64 deliberately, not by default. Reserve it for assets that are small (a few kilobytes), reused, and needed during the critical render path — icons, logos, placeholders and the like. Keep photographs, large illustrations and anything that changes often as external, cacheable files served with long cache lifetimes and modern formats.
Always match the MIME type to the real bytes, store the encoding choice consistently across your API (raw Base64 vs full Data URI — pick one and document it), and strip whitespace before embedding a string in code, since line breaks that are harmless in a text file can break a CSS or HTML attribute. The minified output style in this tool produces a single safe line for exactly this reason.
Finally, measure. Inlining is a trade-off, and the only way to know it helped is to look at your real load waterfall and Core Web Vitals. Use the performance analyzer here to get a quick verdict, then verify in the field. When an inlined asset grows past the point where it pays off, move it back out to a file — the right answer changes as your images and pages do.
| Output | Type | Transparency | Best for |
|---|---|---|---|
| Raw Base64 | Text string | Preserved | API payloads, JSON fields, databases |
| Data URI | data: URL | Preserved | src / href / CSS url(), self-contained assets |
| HTML <img> | Markup | Preserved | Emails, single-file HTML, quick embeds |
| CSS background | Stylesheet rule | Preserved | Inline backgrounds, sprites, critical CSS |
| Markdown | Markdown image | Preserved | READMEs, docs, notes, wikis |
| JSON object | Structured | Preserved | Config files, API responses, manifests |
* TIFF, HEIC and HEIF are encoded to Base64 exactly as supplied; the browser cannot rasterise them, so resize/convert/compress options are skipped for those formats.
Resize and convert to WebP first. Base64 multiplies every byte by ~1.33, so a smaller source means a far shorter string.
APIs usually want bare Base64; browsers and CSS need the full data: URI. This tool gives you both — copy the right one.
Keep inlined images under ~5 KB. Larger ones bloat your HTML/CSS and lose the browser cache — serve them as files instead.
Use the minified, single-line output before pasting into a CSS or HTML attribute. Line breaks can silently break the value.
Base64’s 33% overhead largely disappears under gzip/brotli. Check the analyzer’s gzip estimate for the real transfer cost.
For small SVGs, a percent-encoded Data URI is readable and often smaller than Base64. The decoder handles both directions.
Every image is read and encoded with the browser’s File, Canvas and ArrayBuffer APIs on your own machine — there is no upload, no server processing and nothing is ever permanently stored. That means there is nothing to leak, nothing to delete, and no waiting on a network. The tool works offline once loaded, and your files are released from memory the moment you close the tab.
The MIME type in the header almost certainly does not match the bytes. Run the string through the validator — it sniffs the real format from the magic bytes and tells you the correct MIME (for example image/jpeg instead of image/png).
Line breaks inside a Base64 value are invalid in a CSS url(). Re-encode with the “Minified / single-line” output style so the entire Data URI is one unbroken line.
Browsers cannot rasterise HEIC, HEIF or TIFF on a canvas, so the optimise (resize/convert) options are skipped for them and the original bytes are encoded as-is. Convert to JPG or PNG first if you need to optimise.
Enable the Optimise panel before encoding: resize to the display size, convert to WebP and lower the quality. Base64 multiplies every byte, so shrinking the source is the most effective fix.
Gmail strips Base64 Data URIs from <img> tags for security. Use a hosted image URL or a CID attachment for Gmail; Apple Mail and Outlook render small Data URIs fine.
The decoded bytes don’t match any image signature — the string may be truncated or not an image at all. Re-copy the complete string, or pick an explicit output format to force the type.