Image to Base64 Encoder / Decoder
For developers. Turn an image into a base64 string you can paste directly into HTML or CSS — or decode one back to a file.
Drop your image here
JPG, PNG, WebP, SVG — we'll convert it to a base64 data URL.
How to encode an image to base64
Drop your image
Drag in any JPG, PNG or WebP. Or switch to the decode tab and paste a base64 string instead.
Copy the base64 output
The full data URI is shown immediately — ready to paste into your code.
Use it
Paste the data URI into an img src attribute, a CSS background-image, or wherever you need it in your code.
Or decode
Paste a base64 string into the decode tab and get the image back as a downloadable file.
Base64 images: when they help and when they hurt
Base64 encoding is a tradeoff. You eliminate an HTTP request — the browser does not need to fetch a separate file — but the encoded string is about 33% larger than the original binary. For small images like a 2KB icon or a 5KB logo, that is a good deal. You save a round-trip to the server and the added size is negligible.
For large images it flips. A 200KB photo becomes a 266KB base64 string, and that string sits inside your HTML or CSS file. The browser has to parse the entire HTML document before it can start rendering anything, so embedding large images this way delays first paint.
The rule of thumb: base64 for small, frequently-used assets (icons, logos, small decorative elements). URL references for anything bigger, especially above-the-fold hero images where load speed matters most.
Using the output
The encoder gives you a complete data URI, which starts with data:, then the image type, then the base64 text. Where it goes depends on the job.
- In HTML, put the whole data URI in the src attribute of an img tag, exactly where a file path would normally go.
- In CSS, wrap it in url() as the value of a background image.
- In JSON or an API payload, store it as an ordinary string. The receiving side can decode it back into a file.
- In an email template, avoid it. Several major mail clients block data URI images, so link to a hosted file instead.
Why the text is bigger than the image
Base64 turns every 3 bytes of the file into 4 characters, so the encoded text is about 33 percent larger than the image itself, plus the short prefix. That sounds costly, and for storage it is. Over the web it matters much less, because servers compress text before sending it, and base64 text compresses well.
We measured exactly how much of that 33 percent survives compression, and why caching is the real cost of inlining images, in our guide to base64 images.
When decoding fails
If a pasted string will not turn back into an image, one of these is almost always the reason.
Spaces and line breaks are removed automatically before decoding, since strings copied out of code editors and emails often pick them up along the way.