A small icon (Base64 pays off)
- Input
- PNG de 1024 bytes (1 KB)
- Expected output
- 1368 caracteres em Base64 (+33%)
For an icon this small, the 344 extra characters cost less than one more HTTP request.
image data URI and Base64
A data URI embeds an image byte-for-byte inside HTML, CSS, or JS as text, using the `data:[mime-type];base64,<data>` format defined by RFC 2397. That removes one separate HTTP request for the file, but trades it for a text version that is always bigger than the original binary, and this tool computes exactly how much bigger before you decide.
For an icon this small, the 344 extra characters cost less than one more HTTP request.
The embedded image gets downloaded again on every page load, bundled with the HTML or CSS that contains it.
The tool ignores the file name and reads the actual bytes to decide the MIME type.
It is a way to represent binary data (like an image) using only ASCII text characters, in the form data:image/png;base64,XXXX. This lets you embed the image directly in HTML or CSS code, with no separate file.
Because Base64 encoding represents every 3 binary bytes with 4 text characters, a fixed 33% overhead (4/3), no matter what format the original image is in.
This tool uses 20,000 characters (about 15 KB of original image) as the practical cutoff: below that, the saved HTTP request tends to be worth more than the 33% overhead; above it, the bigger file and the lost image cache outweigh the saving.
It works both ways: the tool generates the snippet both as the src attribute of an <img> tag and as a CSS background-image value, from the same data URI.
The tool decodes the Base64 and reads the byte signature at the start of the file (for example FF D8 FF for JPEG, or the leading 8 bytes of PNG), instead of trusting the extension or a mistyped file name.
Encoding and decoding happen entirely in your browser. No image is sent to any server.