What is Base64?
Base64 is a way to write binary data, such as the bytes of a picture, using only 64 safe text characters: letters, numbers, plus and slash. Because the result is plain text, it can travel through places that only accept text, such as HTML, CSS, JSON and email.
Base64 is an encoding, not a security feature. Anyone can turn the text back into the image, so do not use it to hide anything.
What is a data URI?
A data URI puts the file inside the address itself. It has the form data:image/png;base64, followed by the encoded text. A browser reads it like a normal image address, but it does not need to download a separate file. You can use it in the src of an image, in a CSS url(), or anywhere else a file address is accepted.
Which output format to choose
| Format | Looks like | Use it for |
|---|---|---|
| Data URI | data:image/png;base64,iVBOR… | Any place that takes an image address. |
| Base64 only | iVBOR… | APIs, JSON and code that adds its own prefix. |
| HTML image | <img src="data:…" alt="" width="32" height="32"> | Pasting a picture straight into a page or an email template. |
| CSS background | background-image: url("data:…"); | Small icons and patterns in a stylesheet. |
| Markdown |  | Readme files and notes that allow inline images. |
Base64 makes files bigger
Base64 turns every 3 bytes into 4 characters, so the text is about 33% bigger than the picture. Here are three examples.
| Original file | Base64 characters |
|---|---|
| 1 KB (1,024 bytes) | 1,368 |
| 10 KB (10,240 bytes) | 13,656 |
| 100 KB (102,400 bytes) | 136,536 |
When embedding an image is a good idea
- Tiny icons and logos. A few kilobytes saves a separate request, and the picture appears with the page.
- Single-file pages and demos. One HTML file that shows its pictures and needs no other files.
- API and JSON data. Many APIs expect an image as a Base64 text field.
- Email templates. Some email programs show embedded images, but many block them. Test in the programs your readers use.
For large photos, a normal image file is usually the better choice. An embedded picture cannot be cached on its own, and it makes the HTML or CSS file bigger, which can slow down the first view of your page. Compress it first with the Image Compressor if you still want to embed it.
A note about SVG
An SVG image is already text, so you can often put it in a page directly, or in a data URI without Base64, and get a smaller result. The Base64 version is still useful when a system only accepts Base64.
Your images stay on your device
The encoding is done by your browser. Your pictures are not sent to our server, stored or logged. Be careful with where you paste the result, because the Base64 text contains the whole picture.