Drop an image to encode
Drag & drop, paste, or pick a file
PNG · JPG · WebP · GIF · SVG — encoded on your device
Image to Base64 — and Back
Encode any image to a Base64 string or data URI with ready-to-paste CSS and HTML snippets, or decode Base64 back to an image — free and right in your browser.
Base64 is one of those quietly essential pieces of plumbing on the web. If you have ever opened a CSS file and seen a background image written out as a giant string of letters and numbers, or copied an image straight into an email template, you have already met it. This guide explains what Base64 and data URIs actually are, when it makes sense to turn an image into Base64, and how to convert in both directions — encoding a file into a string and decoding a string back into a file.
Free tool
Use the Image ↔ Base64 tool at the top of this page to encode any image to a Base64 string or data URI — with copy-ready CSS and HTML — or paste a string and decode it straight back to a downloadable image. Everything runs in your browser.
What Base64 actually is
Computers store images as raw binary — a long sequence of bytes. That works perfectly when a file travels as a file, but many places on the web only safely carry plain text: the body of a CSS rule, a JSON field, an HTML attribute, the headers of an email. Dropping raw binary into those contexts breaks things, because some byte values have special meaning or simply cannot be represented.
Base64 solves this by re-writing binary using a restricted alphabet of 64 safe characters — the letters A–Z and a–z, the digits 0–9, and the symbols + and /, with = used for padding. Every three bytes of the original become four of these text characters. The result is a string you can paste anywhere text is allowed, and that can be reversed exactly back into the original bytes. Nothing is lost and nothing is compressed: Base64 is a representation, not a transformation of the image itself.
What a data URI adds
A bare Base64 string is just the encoded body. A data URI wraps it so a browser knows what it is and can use it directly. The format is:
data:[<media type>][;base64],<data>
For a PNG that looks like data:image/png;base64,iVBORw0KGgo…. The data: scheme tells the browser “the content is right here in the URL,” image/png is the media type, ;base64 says the body is Base64-encoded, and everything after the comma is the encoded image. You can put that whole string anywhere a URL would normally go — a CSS url(), an <img src>, a favicon link — and the browser renders it without making a separate network request.
When to encode an image as Base64
Inlining an image as a data URI is a trade-off, so it pays to know when it helps.
- Small, frequently-used icons and logos. Inlining a tiny icon into your CSS removes one round-trip to the server. For assets that appear on every page, that saved request can matter.
- HTML emails. Many email clients block linked images by default but will display an inlined one. Embedding a small logo as a data URI makes sure it always shows.
- Single-file deliverables. When you need a self-contained HTML file, a standalone SVG, or a JSON payload that carries its own imagery, Base64 lets the image travel inside the document.
- Avoiding a hosting step. Sometimes you just need the image in the code right now and do not want to upload it somewhere first.
And when to avoid it:
- Large photos. Base64 adds about a third to the byte size, and an inlined image cannot be cached separately by the browser — it is re-downloaded every time the CSS or HTML around it changes. For big images, a normal hosted file is faster.
- Anything reused across many pages at large size. A cached URL beats re-sending the bytes inline each time.
A good rule of thumb: inline assets under a few kilobytes, link everything else.
How to convert an image to Base64
Encoding is the common direction. With the tool above:
- Open your image. Drag a PNG, JPG, WebP, GIF, or SVG onto the tool, choose a file, or paste from your clipboard.
- Pick the output you need. Switch between the raw Base64 body, the full
data:URI, a CSSbackground-imagerule, or an<img>tag — each is generated for you. - Copy or download. Tap Copy to put it on your clipboard, or download the string as a
.txtfile for later.
Because the tool reads the file’s exact bytes, the data URI is a faithful, lossless copy of your original — encoding a PNG keeps its transparency, and encoding a JPG does not re-compress the photo.
How to convert Base64 back to an image
Going the other way — turning a string back into a file — is just as easy, and useful when you find a data URI in code and need the actual image:
- Paste your Base64. On the Decode tab, drop in the raw Base64 body or a full
data:image/…;base64,…URI. Line breaks, quotes, andurl()wrappers are stripped automatically. - Decode. The image appears instantly in a preview, with its detected type and size.
- Download. Save the rebuilt image; the file gets the correct extension automatically.
The decoder is deliberately forgiving — it repairs missing padding and handles URL-safe Base64 — but it also checks that the decoded bytes really are an image, so a truncated copy/paste fails with a clear message instead of saving a broken file.
A note on size and performance
It is worth repeating because it surprises people: a Base64 string is always bigger than the file it came from, by roughly 33%. That overhead is the cost of using only text-safe characters. It does not mean your image got worse — decode it and you get back exactly what you started with. The size only matters for transport: it is why inlining shines for small assets and hurts for large ones.
Privacy and how this tool works
The encoding and decoding both happen in your browser using standard web APIs — your image is turned into text, and text is turned back into an image, on your own device. How any data associated with the tool is handled is described in our privacy policy. There is no account to create and no watermark on anything you produce.
Whether you are inlining an icon to shave a request off a page load, embedding a logo in an email, or pulling an image back out of a data URI you found in someone’s stylesheet, converting between images and Base64 is a small skill that comes up constantly in web work — and the tool above handles both directions in a couple of clicks.
Frequently asked questions
Is this Base64 image tool free?
Yes — completely free, with no watermark and no sign-up. You can encode and decode as many images as you like.
What is a Base64 image (data URI)?
Base64 is a way of writing binary data — like an image file — using only plain text characters. A data URI wraps that text with a prefix like data:image/png;base64, so a browser can treat the string itself as the image, with no separate file to download.
How do I convert an image to Base64?
On the Encode tab, drop or choose an image. The tool instantly shows the raw Base64 string, the full data URI, and ready CSS and HTML snippets. Tap Copy, or download the string as a .txt file.
How do I convert Base64 back to an image?
Switch to the Decode tab, paste a Base64 string or a full data: URI, and click Decode. The image previews instantly and you can download it as a file in its original format.
Why is the Base64 string larger than my image file?
Base64 encoding adds about 33% to the size, because every 3 bytes of binary become 4 text characters. That's expected. Inline data URIs are best for small images (icons, tiny logos); for larger images a normal file or URL is usually smaller and caches better.
Does encoding change my image quality?
No. Base64 is a lossless text representation of the exact original bytes — it doesn't re-compress or alter the image at all. Decoding gives you back a byte-for-byte identical file.
Which image formats are supported?
You can encode PNG, JPG, WebP, GIF, BMP, SVG, AVIF, and ICO files. Decoding detects the format automatically from the data and gives the download the correct extension.
Where is my image processed?
The encoding and decoding happen in your browser, so the result is created on your own device. How any data associated with the tool is handled is described in our privacy policy.
Can I use the data URI in CSS or HTML?
Yes. The Encode tab gives you a ready background-image CSS rule and an <img> tag with the data URI already filled in — just copy and paste. Inlining small images this way removes an extra network request.
Does it work on phones?
Yes. The encoder and decoder work on phones and tablets — the buttons, copy actions, and paste box are all touch-friendly.
More image tools
Crop an image
Crop to any ratio or an exact pixel size.
Image toolCompress an image
Shrink file size without visible quality loss.
Image toolResize an image
Change dimensions to exact pixels or presets.
Image toolConvert HEIC to JPG
Turn iPhone HEIC photos into universal JPG.
Image toolConvert image format
PNG, JPG and WebP — convert any to any.