What you can do here
- PNG to Base64
- JPG / JPEG to Base64
- GIF to Base64 (animated or static)
- WebP to Base64
- SVG to Base64
- BMP to Base64
- AVIF to Base64
- APNG (animated PNG) to Base64
- Base64 to image, with the file type detected
- Copy as CSS, an HTML tag, Markdown or a JSON field
Pick a format button to see notes for that type, or just drop any image — the format is detected from the file. Each format has its own link, such as /image-to-base64?format=jpg.
How image to Base64 conversion works
The browser reads the file's bytes with FileReader.readAsDataURL(). Base64 takes every 3 bytes (24 bits), splits them into four 6-bit groups, and writes each group as one of 64 safe characters (A–Z a–z 0–9 + /), padding the end with =. The result is prefixed with the image's MIME type:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==
This is an encoding, not a re-compression: the original bytes come back exactly when decoded. JPEG quality, EXIF metadata, color profiles, GIF and APNG animation frames, timing and loop counts are all kept. The trade-off is size — 4 characters for every 3 bytes, about 33% larger.
Format notes
| Format | Data URL prefix | What to know |
|---|---|---|
| PNG | data:image/png;base64, | Lossless with transparency; the usual choice for icons, logos and UI sprites. |
| JPG / JPEG | data:image/jpeg;base64, | Photos. Quality and EXIF stay exactly as in the file. A 2 MB photo becomes about 2.7 million characters, so keep inlined JPGs small. |
| GIF | data:image/gif;base64, | All frames, delays and the loop count survive, so an animated GIF still animates from a data URI. |
| WebP | data:image/webp;base64, | Usually 25–35% smaller than PNG or JPG, which keeps the Base64 string shorter. Supported by all current browsers. |
| SVG | data:image/svg+xml;base64, | Works, but SVG is text: a URL-encoded data:image/svg+xml,<svg… is often shorter than Base64. |
| BMP | data:image/bmp;base64, | Usually uncompressed, so strings get huge. Convert to PNG first with the image converter for a much shorter result. |
| AVIF | data:image/avif;base64, | Smallest files for photos. Renders in current Chrome, Edge, Firefox and Safari 16+, but not in older browsers or many email clients. |
| APNG | data:image/png;base64, or data:image/apng;base64, | Animated PNG with full alpha. Frames are preserved; browsers that support APNG play it from a data URI. |
How much bigger does Base64 make an image?
| Image size | Base64 length | Good idea to inline? |
|---|---|---|
| 1 KB icon | ≈ 1,370 characters | Yes — saves a request |
| 10 KB logo | ≈ 13,700 characters | Usually fine |
| 100 KB image | ≈ 137,000 characters | Rarely — blocks rendering and cannot be cached separately |
| 2 MB photo | ≈ 2.8 million characters | No — link the file instead |
Using the output
<img src="data:image/png;base64,iVBORw0KGgo..." alt="Logo">
.icon { background-image: url("data:image/svg+xml;base64,PHN2Zy..."); }
{ "avatar": "data:image/jpeg;base64,/9j/4AAQSkZJRg..." }
In code
// Browser
const url = await new Promise(r => { const f = new FileReader(); f.onload = () => r(f.result); f.readAsDataURL(file); });
# Python
import base64; b64 = base64.b64encode(open("logo.png", "rb").read()).decode()
# Command line (macOS / Linux)
base64 -i logo.png | tr -d '\n' # macOS
base64 -w 0 logo.png # GNU coreutils
Common questions
How do I convert an image to Base64?
Drop the image on the box above, click to browse, or paste it from the clipboard. The data URL appears immediately; choose Copy as to get raw Base64, a CSS rule, an HTML tag, Markdown or a JSON field, then click Copy output.
Does converting to Base64 reduce quality or compress the image?
Neither. Base64 re-writes the same bytes as text, so quality, metadata and animation are untouched, and the result is about 33% larger than the file. To make it smaller, compress or convert the image first (for example BMP to PNG, or PNG to WebP).
Will an animated GIF or APNG still play?
Yes. The bytes are encoded exactly, so every frame, its timing and the loop count are preserved, and the image animates wherever the data URI is used as an image source.
How do I convert Base64 back to an image?
Switch to Base64 → Image and paste a full data URL or raw Base64. The tool detects PNG, JPEG, GIF, WebP, BMP, AVIF and SVG from the first bytes, shows a preview, and downloads the file with the right extension.
Why does my AVIF data URI show as a broken image?
The app displaying it cannot decode AVIF. Current browsers can, but older browsers and many email clients cannot. Use a PNG, JPG or WebP data URI there instead.
Is my image uploaded anywhere?
No. FileReader reads the file inside your browser tab; nothing is sent to a server, so it is safe for private images and works offline once the page has loaded.