How to convert an image to Base64
- 1.
Choose an image
Drop the file onto the box, pick it from your device or paste it from the clipboard (Ctrl+V).
- 2.
Pick the output format
Data URI, raw Base64, a ready CSS rule, an HTML <img> tag or Markdown.
- 3.
Copy the code
Click “Copy” or download the result as a .txt file.
- 4.
Decode (optional)
In “Base64 → image” mode, paste the text, check the preview and download the file.
What are Base64 and data URIs?
Base64 writes binary data (such as a PNG file) using 64 text-safe characters: A-Z, a-z, 0-9, “+” and “/”. Every 3 bytes of the file become 4 characters, so the text is about 33% longer than the file: a 30 KB image turns into roughly 40 KB of text (exactly 4 × ⌈n ÷ 3⌉ characters).
A data URI is Base64 with a prefix that states the data type, for example data:image/png;base64,iVBORw0KGgo…. The browser treats it like a file address, so you can put it in an image’s src or in a CSS url().
When should you embed images as Base64?
- Yes: small icons and patterns (up to a few KB), images in email templates, single-file HTML pages without external assets, data in JSON or API payloads, tests and prototypes.
- No: photos and large graphics. Base64 adds 33% to the size, is not cached separately by the browser and blocks CSS and HTML parsing. Serve large images as normal files, ideally WebP.
For SVG, a URL-encoded SVG string is often shorter than Base64 and works just as well in CSS.
How long will the encoded image be?
Base64 length is 4 × ⌈n ÷ 3⌉ characters, where n is the file size in bytes. A data URI adds its prefix, e.g. data:image/png;base64, is 22 characters.
| File | Size | Base64 length | Embed it? |
|---|---|---|---|
| SVG icon | 1 KB (1024 B) | 1,368 characters | yes |
| PNG icon 64×64 | 4 KB | about 5,500 characters | yes |
| PNG logo | 30 KB | about 41,000 characters | in emails rather than on websites |
| JPG photo | 500 KB | about 683,000 characters | no |
Above 100 KB the tool shows a warning. The file is encoded byte for byte without re-compression, so the Base64 also contains the photo’s EXIF metadata (including GPS). Before embedding a photo, strip it with the EXIF remover and shrink it with the image compressor.
Common decoding problems
- Truncated text - Base64 copied from logs or a console is often cut off. Typical symptom: an “invalid Base64” message or an image cut in half.
- Spaces and line breaks - removed automatically, so you can paste text wrapped every 76 characters as in MIME emails.
- URL-safe variant - “-” and “_” are turned back into “+” and “/”, and missing “=” padding is added.
- Code snippets - paste a whole CSS rule with
url(…)or an<img src="…">tag and the tool extracts the data itself. - Data that is not an image - the type is detected from the file signature (JPG, PNG, GIF, WebP, BMP, ICO, AVIF, SVG), not just the data: prefix. Base64 containing a PDF or plain text is rejected.
Usage examples
<img src="data:image/png;base64,iVBORw0KGgo…" alt="Logo">
.icon {
background-image: url("data:image/svg+xml;base64,PHN2Zy…");
}
Frequently asked questions
Why is Base64 larger than the file?
+
How do I convert Base64 back to an image?
+
Are SVG files supported?
+
Is Base64 encryption?
+
Are my files uploaded to a server?
+
Updated: