Image to Base64 and Base64 to Image
Encode an image as a Base64 string or decode a Base64 string back into an image.
What is Base64 image encoding?
Base64 is a way of writing binary data, such as the bytes of a PNG or JPG file, using only 64 safe text characters: the letters A to Z, a to z, the digits 0 to 9, plus and slash. Because the result is plain text, an image can be pasted into places that only accept text. That includes HTML and CSS files, JSON payloads, email templates, configuration files and database fields. When the text is prefixed with a short label such as data:image/png;base64, it becomes a data URI that a browser can display directly.
This Image to Base64 Converter works in both directions. Choose a picture and it produces the Base64 string, with or without the data URI prefix, ready to copy. Or paste an existing Base64 string and it turns it back into a viewable, downloadable image. The decoder detects the image type from the string itself, so even a bare string with no prefix usually works.
Conversion happens locally in your browser. Your image is not uploaded to a server and the Base64 text is not stored anywhere, so you can safely encode logos, icons and private screenshots. The tool is free, has no file-count limit and needs no account.
How to use the Image to Base64 Converter
- Pick the direction: Use the tabs at the top of the tool. Image to Base64 encodes a picture, and Base64 to Image decodes a string back into an image.
- Encode: choose a file: Select a PNG, JPG, WebP, GIF or SVG file. The preview appears next to the generated text.
- Decide on the prefix: Keep Include data URI prefix on if you want to paste the result straight into an img tag or a CSS url(). Turn it off for APIs that expect only the raw Base64 payload.
- Copy the output: Press Copy to clipboard. The side panel also shows how many characters the string contains, which helps you judge whether inlining is sensible.
- Decode: paste a string: Switch to Base64 to Image, paste your string or full data URI, and press Decode to image. Whitespace and line breaks are ignored.
- Preview and download: If the string is valid, the picture appears and a Download button lets you save it with the correct extension. Invalid strings produce a clear error message.
Features
- Two-way conversion: Encode images to Base64 and decode strings back to pictures in a single page.
- Data URI toggle: Copy either the full data:image string or the bare Base64 payload.
- Automatic type detection: Strings that start with markers for PNG, JPG, GIF, WebP or SVG are recognized without a prefix.
- Instant preview: See the image beside the text so you know the conversion worked.
- Character count: Know the exact length of the output before pasting it into code.
- Private by design: All encoding and decoding happens in your browser, not on a server.
Examples
- Embedding a logo in an HTML email: Many email clients block external images. Inlining a small logo as a data URI keeps it visible in clients that allow it, although support varies, so always test across inboxes.
- Shipping a placeholder in a single CSS file: A 1 KB blur-up placeholder encoded as Base64 can sit inside your stylesheet, saving an extra network request during the first paint.
- Debugging an API response: A backend returns an avatar as a long Base64 string. Paste it into the decoder to see what the image actually looks like and confirm the format.
Common uses
- Front-end development: Inline icons and tiny images to cut HTTP requests on critical pages.
- Email templates: Embed small graphics in HTML newsletters where hosting images is awkward.
- API testing: Inspect Base64 images returned by or sent to REST and GraphQL endpoints.
- Mobile apps: Store small assets inside JSON configs or bundle them with app code.
- Documentation: Include self-contained example images in Markdown or HTML docs without hosting files.
- Database and config storage: Save thumbnails as text in systems that cannot store binary files.
Tips
- Base64 makes data about 33 percent larger than the original file, so reserve it for small images such as icons and thumbnails.
- Large photos are better served as normal files with caching. A multi-megabyte Base64 string slows down page parsing.
- Compress or resize an image before encoding to keep the string short. The Image Optimization tools on this site can help.
- Remember that inline images cannot be cached separately by the browser, so repeating the same string on many pages wastes bandwidth.
- For SVG, you can often use plain URL-encoded SVG in CSS, which is shorter than Base64, but Base64 remains the safest choice for broad compatibility.
- When decoding, copy the entire string. A single missing character at the end can make the image fail to load.
- Strip the data URI prefix if your API documentation asks for raw Base64, and add it back when displaying in a browser.
- Treat Base64 as encoding, not encryption. Anyone can decode it, so never use it to hide sensitive pictures.
Frequently asked questions
What is a Base64 image?
It is an image file written as a long string of text using 64 printable characters. The text can be embedded in HTML, CSS or JSON and decoded back into the original image by browsers and programs.
What is the difference between Base64 and a data URI?
Base64 is the encoding of the bytes. A data URI is Base64 plus a short header such as data:image/png;base64, that tells a browser what kind of file follows. You need the full data URI for an img src, and often just the raw Base64 for APIs.
Why is the Base64 string bigger than my image?
Base64 uses four text characters for every three bytes of data, so the output is about 33 percent larger. Compressing the image first is the best way to keep the string manageable.
Is it safe to put my image into this converter?
Yes. Encoding and decoding run in your browser, and nothing is uploaded to a server. You can use it for private logos, screenshots and documents.
Which image formats can I encode?
Any image your browser can open, including PNG, JPG, WebP, GIF and SVG. The data URI prefix is generated from the file type automatically.
Can I decode a string without the data:image prefix?
Yes. The tool inspects the beginning of the string to guess the format, defaulting to PNG when it cannot tell. If the picture fails to display, add the correct prefix manually and try again.
Why does my decoded string show an error?
Common reasons are a truncated string, extra characters copied from a code editor, quotes around the value or a string that is not an image at all. Copy the whole text again and make sure it contains only Base64 characters.
Should I use Base64 images on my website?
Only for very small assets. Inlined images avoid a network request but cannot be cached on their own and increase HTML or CSS size. Larger images are better as separate files served with caching and a CDN.
Is Base64 a form of encryption?
No. It is a reversible encoding that anyone can decode in a second. Do not use it to protect private pictures.
Is there a size limit?
There is no fixed limit in the tool, but very large images produce extremely long strings that can slow your browser and clipboard. Resize large photos first.
Troubleshooting
- The decoded image shows as broken: The string is probably truncated or contains extra characters such as quotation marks or line numbers. Copy only the Base64 text and try again.
- The browser refuses to display my data URI: Check that the prefix reads data:image/png;base64, with a comma at the end and that the media type matches the real file type.
- The encoded text is far too long: Resize or compress the image before converting it. A 20 KB picture produces about 27,000 characters, while a 2 MB photo produces over 2.7 million.
- My API rejects the string: Some APIs want the raw payload without the data:image prefix. Turn off Include data URI prefix and copy again.
- The image works in the browser but not in my email client: Several email clients block data URIs. Test in your target clients, or host the image on a secure server and link to it instead.