What a Base64 PNG Is
A PNG file is a stream of bytes. Base64 is a way to write any bytes using only 64 safe text characters: letters, digits, plus and slash. A base64 png is simply the bytes of a PNG file written in that alphabet, so the image can live inside a text file, a style sheet, a JSON value or an email.
The tool reads the file in your browser, encodes the bytes and builds the text. It works the same way for JPG, GIF, WebP, AVIF, BMP, ICO and SVG files. To encode ordinary text instead of a file, use Base64 Encode.
Convert an Image to Base64: A Worked Example
Here is a tiny PNG of 70 bytes after conversion. The bare Base64 text is 96 characters:
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGNg+M/A8B8ABQACAam5sAAAAABJRU5ErkJggg==Every PNG starts with the same eight bytes, so every base64 png starts with iVBORw0KGgo. JPEG files usually start with /9j/, GIF files with R0lGOD and WebP files with UklGR. If your string starts with something else, it is not one of those formats.
The same text as a data URI, which is what you paste into an image source:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGNg+M/A8B8ABQACAam5sAAAAABJRU5ErkJggg==Data URI, CSS, HTML and Markdown Output
The format menu changes only how the same Base64 text is wrapped. For the example above, with the file name tiny-dot.png:
- Data URI:
data:image/png;base64,.... Use it anywhere a browser expects an image address. - CSS:
background-image: url("data:image/png;base64,...");. Paste it into a rule. - HTML img:
<img src="data:image/png;base64,..." alt="tiny dot">. The alt text is made from the file name, so check it and write a proper description if the image matters to readers. - Markdown:
. Not every Markdown renderer allows data URIs, so test it where you will use it. - Base64 only: the bare text with no prefix, for APIs and JSON fields that ask for a Base64 string and give the type separately.
The line length setting applies to Base64 only. Some older tools and email formats expect lines of 76 characters, and PEM-style text uses 64. A data URI is never split, because a line break inside it would break the address.
How Much Bigger Does Base64 Make an Image?
Base64 writes every 3 bytes as 4 characters, so the text is about one third larger than the file. A file of 10,000 bytes becomes 13,336 characters. Very small files are a little worse because of padding: the 70-byte example above becomes 96 characters. The tool shows the exact number for each image.
A data URI also cannot be cached on its own. If the same icon is used on ten pages, the string is downloaded ten times as part of those pages, while a normal image file is downloaded once and reused. That is why the tool warns you at about 100 KB of encoded text.
When to Inline an Image and When Not To
Inlining can make sense for small, rarely changing images:
- Tiny icons and background patterns in a single CSS file, so the page does not need an extra request.
- HTML email, where linked images are often blocked until the reader allows them. Mail clients treat data URIs differently, so test with the clients you care about.
- Single-file pages, demos and bug reports where everything has to be in one document.
- JSON or API requests that carry a small image as a text field.
For photos and large graphics, link a normal file instead. Inlined data makes the HTML or CSS bigger, delays other content and cannot be cached separately. Photos also tend to carry location and camera details, which you can check and remove first with the EXIF Remover.
SVG to Base64
An SVG is already text, so Base64 is not the only choice. You can put SVG markup directly in a page, or use a URL-encoded data URI, which is often shorter than Base64. Base64 still has one advantage: the string contains no quotes, angle brackets or spaces, so it never breaks the attribute or CSS rule it sits in.
This tool detects SVG from the file contents and uses the type image/svg+xml. If you need a PNG instead, convert it first with SVG to PNG.
Limits and Things to Know
- Each file can be up to 5 MB and you can add 20 at a time. A 5 MB image becomes about 7 million characters, which is more than most editors handle comfortably.
- The tool does not resize, compress or change the image. The bytes in the output are the bytes of your file.
- The type in the data URI is found by looking at the start of the file, not the file name. A file called photo.png that is really a JPEG is labeled as JPEG.
- If the start of a file is not a known image format, the tool falls back to the type your browser reports, and refuses files that are not images.
- To turn Base64 text back into a picture, use Base64 to Image. For plain text, see Base64 Decode. For a PDF file, use PDF to Base64.
Your Images Stay in Your Browser
The file is read and encoded by code running in your browser tab. It is not sent to a server and is not stored. Closing or reloading the page removes it. See the Privacy Policy for details.