About this tool
Convert PNG, JPG, GIF and WebP images to Base64, data URLs, HTML or CSS snippets, or decode Base64 back to a downloadable image. Original bytes are preserved without re-encoding.
Typical uses
- Inline a small icon in CSS or HTML
- Inspect a Base64 image from an API response
- Turn email template images into data URLs
How to use
Choose, paste or drop a PNG, JPG, GIF or WebP and select Base64, data URL, HTML or CSS output.
To decode, paste Base64 or a data URL, inspect the preview and download the original image. Copy and downloads include the full result.
Upload a PNG logo and choose a data URL for an img src, or plain Base64 for an API field. Decoding preserves original PNG, GIF and WebP animation bytes.
Original bytes are preserved without re-encoding. Up to 10 MB, 16 MP and 8192 px per edge. Animation: 200 frames and 120 million canvas-pixels × frames. SVG, HTML, remote URLs and MIME mismatches are rejected. Long output is shortened only in preview.
Base64 is usually larger than the binary file and is not image compression. HTML and CSS snippets are displayed as text only. SVG and remote image loading are unsupported.
How long each output format is
Base64 writes every 3 bytes as 4 characters and pads a short final group with =, so raw Base64 is always 4 × ⌈bytes ÷ 3⌉ characters long. The other three formats only add fixed text around it: the data URL prefix data:image/png;base64, is 22 characters for PNG and GIF (23 for JPEG and WebP), the HTML snippet adds 21 more and the CSS snippet 26 more. These are the character counts for a PNG under each “Output format” option, the same number the tool shows in the output label:
| Image size (bytes) | Raw Base64 | Data URL | HTML <img> | CSS background-image |
|---|---|---|---|---|
| 43 B (43) | 60 | 82 | 103 | 108 |
| 70 B (70) | 96 | 118 | 139 | 144 |
| 1 KiB (1,024) | 1,368 | 1,390 | 1,411 | 1,416 |
| 4 KiB (4,096) | 5,464 | 5,486 | 5,507 | 5,512 |
| 100 KiB (102,400) | 136,536 | 136,558 | 136,579 | 136,584 |
| 1 MiB (1,048,576) | 1,398,104 | 1,398,126 | 1,398,147 | 1,398,152 |
| 10 MiB (10,485,760) | 13,981,016 | 13,981,038 | 13,981,059 | 13,981,064 |
- “Output (read only)” shows only the first 100,000 characters and then says “Preview shows the first 100,000 characters. Copy and download include the complete output.” In practice raw Base64 fits completely only for images up to 75,000 bytes, and a PNG data URL only up to 74,982 bytes. For anything larger use “Copy complete output” or “Download text” rather than selecting the text box by hand.
- The HTML snippet is always <img src="…" alt="" />. An empty alt marks a decorative image; if the image carries information, add a text alternative after pasting. The CSS snippet is a single background-image declaration with no size or background-size.
- “Download text” saves “original name.base64.txt” (UTF-8 plain text) in the output format currently selected; “Download original image” saves the original bytes. The characters \ / : * ? " < > | in the name become - and leading dots are removed:
| Original name | “Download original image” | “Download text” |
|---|---|---|
| logo.png | logo.png | logo.base64.txt |
| my:logo?.final.png | my-logo-.final.png | my-logo-.final.base64.txt |
| .hidden.png | hidden.png | hidden.base64.txt |
An image decoded from Base64 has no original name, so it is called image.<extension>: a GIF gives image.gif and image.base64.txt. Neither direction recompresses anything, which also means EXIF data in the file (capture time, GPS position) goes into the Base64 unchanged. To leave it out, export a clean copy with the metadata tool first and encode that.
What the decoder accepts
Paste into “Raw Base64 or an image data URL” on “Base64 → Image” and press “Decode and preview”. The tool trims surrounding whitespace, recognises an optional data: prefix, removes every space, tab and line break inside, and then checks the result strictly against the standard Base64 alphabet. Every row below is an actual result:
| Pasted text | Result | Why |
|---|---|---|
| iVBORw0KGgoA…↵…rkJggg== | Decoded and previewed | Mail-style Base64 wrapped every 76 characters, or a JSON field broken over lines, is fine: line breaks are removed |
| DATA:IMAGE/PNG;BASE64,iVBORw0KGgo… | Decoded and previewed | data:, the type and ;base64, are case-insensitive |
| data:image/png;base64,R0lGODlh… | The declared MIME type does not match the image bytes. | The prefix says PNG but the bytes are a GIF: the type is read from the file header and a mismatch is refused |
| data:image/jpg;base64,… | Data URLs must use PNG, JPEG, GIF or WebP with ;base64,. | It must be image/jpeg; image/jpg is not accepted |
| data:image/png;charset=utf-8;base64,… | Data URLs must use PNG, JPEG, GIF or WebP with ;base64,. | No other parameters such as charset are allowed in the prefix |
| data:image/svg+xml;base64,PHN2Zy8+ | Data URLs must use PNG, JPEG, GIF or WebP with ;base64,. | SVG data URLs are always refused |
| PHN2ZyB4bWxucz0i… | Only PNG, JPEG, GIF and WebP images are supported. SVG, HTML and remote URLs are not accepted. | Removing the prefix does not help: the decoded header is not a raster image |
| R0lGODlhAQABAIAAAP___wAA… | Invalid Base64. Check its alphabet and trailing = padding. URLs, URL-safe Base64 and HTML/CSS snippets are not accepted. | URL-safe Base64 (- and _ instead of + and /) is refused; change - back to + and _ back to / first |
| …RU5ErkJggg | Invalid Base64. Check its alphabet and trailing = padding. URLs, URL-safe Base64 and HTML/CSS snippets are not accepted. | Missing = padding, so the length is not a multiple of 4 |
| <img src="data:image/png;base64,…" alt="" /> | Invalid Base64. Check its alphabet and trailing = padding. URLs, URL-safe Base64 and HTML/CSS snippets are not accepted. | Strip an HTML or CSS snippet down to the data URL first |
| https://example.com/logo.png | Invalid Base64. Check its alphabet and trailing = padding. URLs, URL-safe Base64 and HTML/CSS snippets are not accepted. | The tool never downloads a URL |
| QR== | Invalid Base64. Check its alphabet and trailing = padding. URLs, URL-safe Base64 and HTML/CSS snippets are not accepted. | The spare bits before the padding are not zero, a non-canonical encoding |
| QQ== | Only PNG, JPEG, GIF and WebP images are supported. SVG, HTML and remote URLs are not accepted. | Valid Base64, but it decodes to a single byte, which is not an image |
| iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAA | The image could not be decoded or its file structure is incomplete. Check the original image. | A truncated PNG: the structure check finds missing chunks and no end marker |
- RFC 4648 defines base64url as a separate encoding that should not be treated as standard Base64, and this tool accepts only the standard alphabet. Image fields in JWTs and some APIs use base64url and often drop the =, so convert them and pad to a multiple of 4 first.
- The general data URL syntax lets you omit the type or add parameters (RFC 2397), but this tool accepts exactly one form: data:image/png, image/jpeg, image/gif or image/webp followed by ;base64,.
- The text box takes at most 14,046,552 characters: a 10,485,760-byte (10 MB) image is 13,981,016 characters of Base64, plus 64 KB of room for a prefix and line breaks.
Checks the image itself must pass
Whether you choose a file or paste Base64, the tool walks the file structure block by block, lets the browser decode the image once, and only shows a result when the decoded width and height match the header. What it checks:
- Dimensions: at most 8,192 px per side and 16,000,000 pixels in total. A 8192 × 4096 long image (about 33.5 million pixels) is refused; 4000 × 4000 is exactly 16 million and passes.
- Structure: a PNG must start with IHDR and end with IEND; a JPEG needs scan data and must end with the FFD9 marker; a GIF must end with 3B; a WebP RIFF length must equal the file size. Any byte after the end marker (for example another file appended to the image) also counts as an incomplete structure.
- When the browser decodes the image, swapped width and height still count as a match, so phone JPEGs with an EXIF rotation pass. Decoding that takes longer than 15 seconds is treated as a failure.
- For a chosen file, the type reported by the browser must be PNG, JPEG, GIF or WebP; if it reports no type, the header decides.
Animations (GIF, APNG, animated WebP) have two more limits: at most 200 frames, and canvas width × height × frames no more than 120,000,000. The frames actually allowed for some canvas sizes:
| Canvas | Pixels per frame | Maximum frames |
|---|---|---|
| 480 × 270 | 129,600 | 200 |
| 800 × 600 | 480,000 | 200 |
| 1000 × 1000 | 1,000,000 | 120 |
| 1920 × 1080 | 2,073,600 | 57 |
| 4000 × 4000 | 16,000,000 | 7 |
After the checks the tool says “Done. Original image bytes and animation are preserved.” The frame count of an animation appears in the preview details.
Every message and what to do
| Message | Cause and fix |
|---|---|
| Images must be no larger than 10 MB. | The chosen file, or the decoded bytes, exceed 10,485,760 bytes. Compress it first; Base64 is about a third larger than the image, so large images are poor candidates for inlining anyway. |
| Input is too long. Base64 must represent an image no larger than 10 MB. | The text would exceed 14,046,552 characters. A paste that large is blocked and the box keeps its previous content. |
| Maximum 16 MP and 8192 px per side. Resize this image first. | Width or height above 8,192, or more than 16,000,000 pixels. Each animation frame is checked as well. |
| Animation limit: 200 frames and 120 million canvas pixels × frames. | More than 200 frames, or canvas pixels × frames above 120 million; see the table above. |
| The declared MIME type does not match the image bytes. | The type in the data URL prefix does not match the file header, typically a renamed JPEG or a hand-written prefix. Correct the prefix or paste the Base64 without it. |
| Data URLs must use PNG, JPEG, GIF or WebP with ;base64,. | The prefix is not one of the four raster types (image/jpg and image/svg+xml included), carries extra parameters, or lacks ;base64,. |
| Invalid Base64. Check its alphabet and trailing = padding. URLs, URL-safe Base64 and HTML/CSS snippets are not accepted. | Characters outside the alphabet (- _ . : < and so on), a length that is not a multiple of 4, or non-canonical padding. |
| Only PNG, JPEG, GIF and WebP images are supported. SVG, HTML and remote URLs are not accepted. | The decoded bytes do not start with one of the four headers: Base64 of an SVG, HTML, PDF or plain text, for example. Use the SVG converter for SVG. |
| The image could not be decoded or its file structure is incomplete. Check the original image. | The header is right but the structure is incomplete: truncated data, extra bytes after the end, or a browser decode that failed or timed out. |
| Copy failed. Download the text, or select and copy a shorter result manually. | The browser did not allow writing to the clipboard. Download the text instead, or select a short result in the box and copy it by hand. |
Sources
Frequently asked questions
Does it change image quality?
No. Encoding and decoding keep the original bytes without recompression.
How large can images be?
Up to 10 MB, 16 megapixels and 8192 px per side. Base64 is about 1.33× the original size.
Why is SVG rejected?
For safety, SVG, HTML, remote URLs and data with mismatched MIME types are rejected.
Suggest an improvement to this tool
Missing an option, something awkward to use, or a wrong result? Let us know.