Image to Base64 Converter
Encode images to Base64 Data URIs for HTML, CSS and JSON embedding. Decode Base64 strings back to images. Copy as raw string, Data URI, HTML tag or CSS property. 100% browser-based.
<img src="data:image/png;base64,..." />url("data:image/png;base64,..."){"image": "data:image/png;base64,..."}<img src={base64String} />Why Base64 Encoding Exists - and When You Actually Need It
HTTP and HTML were designed around text. When you need to embed binary data - an image - inside a text-based context like an HTML file, a JSON payload, a CSS stylesheet, or an email, you need a way to represent binary bytes as printable characters. Base64 is that encoding: it converts every 3 bytes of binary data into 4 printable ASCII characters, producing a string that can be embedded anywhere text is accepted. The result is a self-contained image reference that requires no separate file, no HTTP request, and no server. The tradeoff is size: Base64-encoded images are approximately 33% larger than their binary originals. For small images - icons, logos, inline SVGs, tiny background textures - this is often acceptable. For large photographic images, an external file with a URL is always the right choice.
Four Output Formats - Which One to Use Where
Raw Base64 is the encoded string without any prefix - just the characters. Use this when an API or application expects the raw encoded data and handles the data: prefix itself, or when you are storing the string in a database field. Data URI is the complete self-contained reference: data:image/png;base64,iVBORw0K... - paste this directly into an img src attribute, a CSS url() function, or any field that accepts an image URL. HTML <img> gives you the complete ready-to-paste tag: <img src="data:..." alt="...">. Drop this into any HTML file and the image renders with no external dependency.CSS background-image wraps the data URI in the CSS property syntax: background-image: url("data:..."); - paste directly into a CSS rule.
The Overhead Percentage - What It Means for File Size
The tool shows a +33% or similar overhead figure after encoding. This is the size penalty of Base64 encoding: every 3 bytes of binary data becomes 4 characters of text, which is a 33.3% increase. A 10 KB PNG becomes approximately 13.3 KB as a Base64 string. For a website, embedding that image inline instead of serving it as a file trades one HTTP request for 3.3 KB of extra HTML size. Whether that is worthwhile depends on context: critical-path small images (CSS sprites, loading spinners, small icons) often benefit from inlining to eliminate a render- blocking request; large images never should. The B64 Length figure shows the character count of the encoded string, which is useful when working with APIs that have character limits on payload fields.
Decoding Base64 Strings Back to Images
The Decode tab reverses the process. Paste any Base64 string - either a full data URI starting with data:image/ or a raw Base64 string without the prefix - and click Decode to Image. The tool renders the image on screen and provides a Download button to save it as a PNG file. This is useful for extracting images embedded in API responses, recovering images from database exports, debugging Base64 strings that may be malformed, or converting data URIs found in existing HTML or CSS back into downloadable files. If the decoded image shows black or does not render, the Base64 string is likely corrupted or truncated.
Common Integration Patterns
React and component libraries: In React, src={base64String}works identically to a URL - import the base64 string as a variable or fetch it from an API and pass it to the src prop directly. Email templates: Many email clients block externally hosted images by default. Embedding small images (logos, dividers, icons) as Base64 data URIs ensures they display immediately without the recipient needing to click "load images." JSON APIs: When an API endpoint needs to accept or return image data in a JSON body, Base64 is the standard encoding - the "image": "data:image/png;base64,..." pattern is used by OpenAI, Google Vision, AWS Rekognition and many other image-processing APIs. CSS sprites and icons: Embedding small SVG icons as Base64 data URIs in a CSS background-image or content property eliminates icon file dependencies entirely.
SVG Files and Base64
SVG files are XML text and can technically be embedded in HTML directly without Base64 encoding - just paste the SVG markup inline. However, Base64-encoding an SVG is still useful when you need to embed it as a background image in CSS (which requires a URL format, not inline markup), or when passing it to a system that expects an image data URI rather than raw XML. The tool accepts SVG files alongside raster formats and encodes them using their image/svg+xml MIME type. After encoding, use the SVG to PNG Converter if you need a rasterised version at a specific pixel dimension instead.
✓Verified by ToollyX Team · Last updated June 2026
Frequently Asked Questions
Disclaimer: All encoding and decoding is performed locally in your browser. No data is transmitted to any server.