About Image to Base64
Base64 turns binary data into plain text, which lets an image travel inside a stylesheet, an HTML email, a JSON payload or a single-file page. It's a handy trick for tiny icons, and you pay for it, because the text is a third larger than the file and can't be cached separately.
Developers use this for small inline assets, email templates, API requests that want image data as a string, and test fixtures. The output tabs give the format you actually need, instead of leaving you to wrap it by hand.
The page shows the file size, the encoded length, and the increase, and warns you when an image is too big for this to be a sensible choice.
How it works
The file's bytes are encoded just as they are. Nothing is drawn to a canvas first, since that would turn every input into a PNG and could make a JPG several times larger. Our test compares the output with the Base64 of the source file and they match exactly, so a JPG stays a JPG and an SVG stays an SVG.
The image type in the data URI comes from the file's first bytes, not its extension, so a mislabeled file still gets a correct data: prefix. Very long results are cut off in the text box only, to keep the page responsive. Copy and Download always give the whole thing.
How to use Image to Base64
- Press Select an image to encode, or drop or paste one onto the page.
- Choose the output: Data URI, Base64 only, CSS, HTML or Markdown.
- Press Copy, or Download as a text file for long results.
- Check the Size increase and read any notice before you embed a large image.
A real run on a 16 px icon
dot.png (16 x 16 PNG)data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAALElEQVR4nGNgGJ5AJC/gPy5MkWaChhCjGa8howYMBgOINQSnZmIMIaiZ7gAABaXF/mlAFnAAAAAASUVORK5CYII=The file is 101 bytes and the Base64 is 136 characters, so the stats panel reports +35%. Very small files round up a little above the usual 33%, because Base64 output is padded to multiples of four characters. A 698.4 KB JPG in the same tool reported 953,612 characters and +33%.
When it helps
- Inlining a tiny icon in a stylesheet to avoid one more network request.
- Embedding a logo into an HTML email signature or template.
- Sending an image in a JSON body to an API that requires Base64.
- Bundling test fixtures or a small avatar placeholder in source code.
- Building a single self-contained HTML file with its images included.
Tips for a better result
- Keep it to small files of a few kilobytes. Beyond that, a normal image file loads better and can be cached by itself.
- Compress first with the Image Compressor, because Base64 adds to whatever size you start with.
- For SVG, a URL-encoded data URI can be smaller than Base64. This tool only outputs Base64.
- Many APIs want Base64 only, without the
data:image/png;base64,prefix. That's what the second tab is for.
Good to know
- Base64 grows data by a third (4 bytes of text for every 3 of data), plus the prefix.
- Some email clients, including several versions of Outlook and Gmail, do not reliably display images embedded as data URIs.
- One file at a time.
- Encoding is not encryption. Anyone can decode the text to get the image back.
Questions people ask
Why is my Base64 about a third larger than the file?
Base64 uses 4 text characters to carry each 3 bytes. That overhead is fixed, whatever the image is. Compression in transit (gzip or Brotli) reclaims part of it, but not all.
What is the difference between a data URI and Base64?
Base64 is just the encoded text. A data URI adds a prefix naming the type, such as data:image/png;base64,, so a browser can use it wherever an image URL would go.
Does this change my image?
No. It doesn't decode, resize or re-compress anything. Decoding the Base64 gives back the same file, byte for byte, including its metadata, which is worth remembering for photos with location data.
When should I avoid Base64 for images?
For anything over a few kilobytes, or anything used on many pages. An inline image can't be cached separately and adds its weight to every page that includes it.
What to use next
- Base64 to Image: to turn encoded text back into a file
- Image Compressor: to shrink the image before encoding it
- SVG to PNG: if a target does not accept SVG data URIs
Learn more
Last reviewed . Read our editorial policy.