Image to Base64 / Base64 to Image

Convert images to Base64 data URLs and vice versa. Useful for embedding in HTML, CSS, JSON, emails.

Image size
Base64 size

What is image Base64 encoding?

Converting images to Base64 encodes the binary image data as an ASCII text string that can be embedded directly in HTML, CSS, JSON, or anywhere text is accepted. This produces a ‘data URI’ like ‘data:image/png;base64,iVBORw0KG…’ which works as an image source. Common uses: embedding small icons inline in HTML (eliminates HTTP request), CSS background-image with embedded data, sending images via JSON APIs that don’t support binary, including images in plain-text emails, or putting images directly into source code. Reverse conversion (Base64 → image) is useful when you need to extract an image from code or test display. This tool handles both directions browser-side – your images never leave your device.

How to use this tool

  1. Choose mode — Image to Base64 (encode) or Base64 to Image (decode).
  2. Upload image (encode mode) — Any common image format – JPG, PNG, WebP, GIF, BMP, SVG.
  3. Choose output format — Full data URI (with prefix – ready to use), Raw Base64 (just the encoded text), CSS background-image declaration, or HTML img tag.
  4. Decode mode: paste Base64 — Paste either data URI or raw Base64. Tool displays the resulting image and offers download.
  5. Copy or use — Encode: copy the output and paste into your code. Decode: download the recovered image.

When to use Base64 images

Good uses:

  • Small icons (under 5 KB) in CSS – eliminates HTTP request
  • Single-page apps with bundled assets
  • Email signatures – images embedded in HTML emails
  • Quick prototypes or demos – everything in one HTML file
  • Sending images via JSON APIs – some APIs don’t support multipart

Bad uses:

  • Large images (over 100 KB) – 33% size overhead makes them slower than HTTP fetch
  • Images used on many pages – HTTP caching is better for repeated assets
  • SEO-important images – search engines can’t index data URI images

Format options:

  • Full data URI: data:image/png;base64,iVBORw… (ready for HTML/CSS)
  • Raw Base64: just the encoded string (for APIs)
  • CSS: background-image: url(‘data:image/png;base64,…’)
  • HTML img: <img src=’data:image/png;base64,…’ alt=”>

Examples

Small 16×16 favicon as data URI:

data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAA...

CSS background:

.icon {
  background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz...');
  width: 24px;
  height: 24px;
}

HTML embedded image (single-file documents):

<img src='data:image/png;base64,iVBORw0KGgo...' alt='logo'>

Useful for: portable HTML reports with embedded charts, email signatures, offline-first apps.

Tips & best practices

  • Use Base64 for images under 5 KB only – larger images perform better via regular URLs and HTTP caching
  • Inline SVGs are usually better than Base64 SVGs – smaller, stylable with CSS, accessible
  • PNG icons under 1 KB are good candidates for Base64 – eliminate HTTP request without bloat
  • For email signatures, Base64 ensures images display even if recipient blocks external content
  • For one-time use (mockups, demos), data URIs simplify single-file delivery
  • Beware Base64 makes HTML/CSS files larger – if you Base64 too many images, the main file becomes slow to download
  • Modern build tools (Webpack, Vite) automatically inline small images as Base64 – the threshold is usually 4-8 KB

Limitations & notes

Base64 increases data size by ~33% (4 chars represent 3 bytes). Best for small images only – large images are inefficient. Cannot be cached separately by browser – if image used on multiple pages, HTTP version with caching is better. Browser memory limits practical use to images under 100 MB or so. Older email clients may not support data URIs – test before relying on it.

Frequently Asked Questions

When should I use Base64 instead of regular image URLs?

When image is small (under 5 KB), used once or in one place, and you need to avoid the HTTP request overhead. Icons in CSS background-image are the most common case. For everything else, regular URLs are better.

Why is Base64 larger than the original image?

Base64 uses 4 ASCII characters to represent 3 bytes – a 33% size increase. This is the cost of converting binary to text-safe encoding. Adding to a PNG that’s already compressed makes it worse than serving the PNG separately.

Can I embed Base64 images in PDF?

Indirectly. PDF supports images natively (PNG, JPEG, etc) without Base64 – PDFs are binary. If you have a Base64 string and want a PDF, decode the Base64 first, then add the image to the PDF using a PDF library.

Does Base64 image hurt SEO?

Slightly. Search engines can’t easily extract or index Base64 images in CSS. Important content images should be regular files with proper alt text. For decorative icons, Base64 is fine.

Can I Base64 encode a video or audio file?

Yes – same data URI mechanism: data:video/mp4;base64,… or data:audio/mp3;base64,… But media files are typically large, so Base64 overhead is substantial. Better to use file URLs for video/audio.

How do I know the right MIME type for the data URI?

Common types: data:image/png, data:image/jpeg, data:image/gif, data:image/webp, data:image/svg+xml. The tool detects from file extension automatically. If you build the data URI manually, match the actual file format.

Is Base64 image secure?

Same security as regular images – no inherent security difference. Risk: if you decode Base64 from untrusted source, malicious image files could exploit browser vulnerabilities. Stick to trusted sources for image data.

Related tools

Base64 Encoder · Image Compressor · Image Format Converter

Copied to clipboard