Image to Base64 Converter
Choose or drop an image to get its Base64 data URI, the raw Base64 and ready-to-paste HTML, CSS and Markdown snippets, with exact sizes. The built-in example, a 16 × 16 PNG, shows the result: 216 bytes become 288 Base64 characters (+33.3%), or 310 as a data URI. The image type is read from the file’s first bytes (PNG, JPEG, GIF, WebP, SVG, AVIF or ICO), not from its name, so the data URI carries the right MIME type. To go the other way, paste a data URI or plain Base64 and the tool previews the image and lets you download it. Files up to 5.0 MB are read in your browser and never uploaded.
Updated Runs in your browser: nothing you enter is uploadedHow this tool works
Image to Base64
Stays in your browser216 bytes become 288 Base64 characters (+33.3%), or 310 as a data URI.
- Detected type
- PNG image (image/png)
- Image file
- 216 bytes
- Base64 text
- 288 characters
- Data URI
- 310 characters
- Base64 overhead
- +33.3% (72 bytes more)
Base64 to image
Decoded 216 bytes from data URI: PNG image.
- Detected type
- PNG image (image/png)
- Decoded size
- 216 bytes
- Base64 characters
- 288
How each image type is recognised
| Format | MIME type | Usual extension | What the tool looks for |
|---|---|---|---|
| PNG | image/png | .png | First 8 bytes 89 50 4E 47 0D 0A 1A 0A (“\x89PNG” and a line-end check) |
| JPEG | image/jpeg | .jpg | First 3 bytes FF D8 FF |
| GIF | image/gif | .gif | Text “GIF87a” or “GIF89a” at the start |
| WebP | image/webp | .webp | Text “RIFF” at byte 0 and “WEBP” at byte 8 |
| AVIF | image/avif | .avif | Text “ftyp” at byte 4, then brand “avif” or “avis” (major or compatible) |
| ICO | image/x-icon | .ico | Bytes 00 00 01 00, then an image count of 1 or more |
| SVG | image/svg+xml | .svg | Text: an “<svg” tag after optional BOM, XML declaration, comments and DOCTYPE |
How much bigger the Base64 form is
| Image file (bytes) | Base64 characters | Data URI characters | Base64 overhead |
|---|---|---|---|
| 1,000 | 1,336 | 1,358 | +33.6% |
| 10,000 | 13,336 | 13,358 | +33.4% |
| 100,000 | 133,336 | 133,358 | +33.3% |
| 1,000,000 | 1,333,336 | 1,333,358 | +33.3% |
Which form to use where
| Form | Use it for | Watch out for |
|---|---|---|
| Data URI | Anywhere a URL is accepted: img src, CSS url(), JSON, e-mail templates | It is part of the file it sits in, so the browser cannot cache the image on its own |
| Raw Base64 | APIs and JSON fields that take image bytes and ask for the type separately | No type information: the receiver must know it is a PNG, JPEG and so on |
| HTML <img> tag | A small icon or logo inside a single self-contained HTML file or e-mail | Add real alt text for anything that is not purely decorative |
| CSS background-image | Small repeating patterns and icons in a stylesheet | A big data URI makes the whole stylesheet slower to download and parse |
| Markdown image | Self-contained notes and README files that cannot link to a separate image | Some Markdown renderers and sites block data: URIs |
How to convert an image to Base64
- Choose the image. Press “Choose an image, or drop it here” and pick a file, or drag one onto the box. Files up to 5.0 MB work; nothing is uploaded.
- Check the type and sizes. The detected type, the exact byte count of the file and the length of the Base64 text and data URI appear next to the preview.
- Copy the form you need. Copy the data URI, the raw Base64, or a ready HTML <img> tag, CSS background-image rule or Markdown image.
- Add alt text. The HTML and Markdown snippets have an empty alt. Fill it in if the image carries meaning.
- Go the other way if you need to. In “Base64 to image”, paste a data URI, a snippet that contains one, or plain Base64 to see the picture and download it as a file.
Frequently asked questions
- What is a data URI?
- A data URI puts a file’s content inside the URL itself, in the form data:<type>;base64,<data>. Browsers treat it like any image address, so it works in an img src, a CSS url() or a Markdown image without a separate file.
- Why is the Base64 text bigger than my image?
- Base64 writes every 3 bytes as 4 characters, so the text is about 33% longer than the file, and a little more for very small files because of padding. The data URI adds its “data:image/png;base64,” prefix on top. The tool shows the exact counts, and the table above lists examples.
- How does the tool know the image type?
- It reads the first bytes of the file. A PNG starts with 89 50 4E 47 0D 0A 1A 0A, a JPEG with FF D8 FF, a GIF with “GIF87a” or “GIF89a”, a WebP with “RIFF” and “WEBP”, an AVIF with an “ftyp” box naming avif or avis, an ICO with 00 00 01 00, and an SVG with an <svg> tag. If the file name or the browser says something else, the bytes win and the tool tells you.
- When should I not use a Base64 image?
- For anything large or reused on many pages. Because the image is inside the page or stylesheet, it cannot be cached separately, it makes that file about a third larger, and it delays rendering. It suits small icons, logos and one-file documents; a normal image file is better for photos.
- Can I turn Base64 back into an image?
- Yes. Paste a data URI, a whole HTML, CSS or Markdown snippet that contains one, or plain Base64 into “Base64 to image”. The tool decodes it, shows a preview, names the detected type and offers the file as a download. Percent-encoded SVG data URIs (data:image/svg+xml,%3Csvg…) work too.
- Does it work with SVG?
- Yes. An SVG is text, so it is recognised by its <svg> tag, even after an XML declaration, comments or a DOCTYPE. It is shown as an image, so scripts inside it do not run. For SVG you can often use a shorter percent-encoded data URI instead of Base64; this tool produces the Base64 form.
- Why does the page say the file is not recognised?
- The file does not start with any of the seven signatures the tool knows. It may be another format (BMP, HEIC, TIFF), a renamed file or damaged. It is still encoded, using the type your browser reported or application/octet-stream, but browsers may not display it as an image.
- Is my image uploaded or saved?
- No. The file is read by your browser and converted on this page, nothing is sent to a server and nothing is stored: reload the page and it is gone. If you allow analytics, the site records only that a button was used, never the image, its name, size or type.
- Do I need to allow data: images in my site’s security policy?
- If your site sets a Content-Security-Policy, add data: to the img-src directive (and to style-src or default-src where a CSS background needs it). Without it, the browser blocks data URI images even when the Base64 is correct.
How it works
The chosen file is read into memory with FileReader as raw bytes. The type is detected from the first bytes: the 8-byte PNG signature, FF D8 FF for JPEG, GIF87a or GIF89a, RIFF…WEBP, an ISO base media “ftyp” box whose major or compatible brand is avif or avis, an ICO header (00 00 01 00 and at least one image), and, for SVG, an <svg> root tag after any BOM, XML declaration, comments and DOCTYPE. The bytes are encoded with the same Base64 encoder as the Base64 Encode & Decode tool (standard alphabet, “=” padding, no line breaks), and the data URI is “data:” plus the detected MIME type plus “;base64,” plus that text. Sizes are exact: the Base64 text has 4 × ceil(bytes / 3) characters, and overhead is that count against the file’s byte count. In the reverse direction, a pasted data URI (Base64 or percent-encoded) or the first data URI inside a snippet is decoded, or, if there is none, the whole text is decoded as Base64 with the same tolerant decoder (whitespace ignored, either alphabet, padding optional). The preview and download are made from the decoded bytes with the detected type.
Sources
More free tools
- Image ResizerResize and compress JPEG, PNG and WebP images by width, height, percent or longest side, and convert the format. Runs in your browser; nothing is uploaded.
- Image Color PickerPick any pixel of an image for its HEX, RGB, HSL and OKLCH value, and get its dominant colors with contrast. Runs in your browser; nothing is uploaded.
- Favicon GeneratorMake a favicon from an image, text or an emoji: PNGs from 16 to 512 px, favicon.ico, an SVG icon, the HTML link tags and a ZIP. Runs in your browser.
- SVG OptimizerMinify SVG code or an .svg file safely: removes metadata, editor data and unused ids, rounds numbers, previews both. Runs in your browser.
- User Agent ParserPaste a User-Agent string to see the browser and version, rendering engine, OS, device type and notable tokens. Explains UA reduction. Runs locally.
- Network Ports ReferenceSearch common TCP and UDP port numbers by number, range or service name: 22 SSH, 443 HTTPS, 3306 MySQL and more, with secure variants and IANA status.
More: Web, URLs, images and networkAll developer toolsAll toolsHome & DIY calculators