Base64 Image Converter: The Complete Guide

What is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that represents binary data (like images, fonts, or audio files) as an ASCII string. It uses 64 printable characters (A-Z, a-z, 0-9, +, /) plus the = padding character to encode data in a format that is safe for text-based protocols such as HTTP, CSS, HTML, and JSON.

When applied to images, Base64 encoding produces a data URI that can be embedded directly into HTML or CSS, eliminating the need for a separate HTTP request to load the image file. The Base64 Image Converter handles both encoding (image to Base64) and decoding (Base64 back to image) with drag-and-drop support.

Base64 encoding increases data size by approximately 33% because every 3 bytes of binary data become 4 characters of Base64 text. This overhead is the primary trade-off to consider when deciding whether to use embedded Base64 images.

Data URI Syntax

A data URI (uniform resource identifier) embeds data directly in a web document. The general syntax is:

data:[<mediatype>][;base64],<data>

Breaking this down:

  • data: — The URI scheme identifier
  • mediatype — The MIME type (e.g., image/png, image/jpeg, image/svg+xml)
  • ;base64 — Indicates the data is Base64-encoded (omit for plain text)
  • data — The actual Base64-encoded payload

A complete data URI for a PNG image looks like this:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==" alt="Pixel">

You can also use data URIs in CSS:

.logo {
  background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0...");
}

Tip: The Base64 Image Converter automatically detects the image type (PNG, JPEG, GIF, WebP, SVG) and generates the correct MIME type in the data URI. Drag and drop any image to get started.

Encoding Images to Base64

The encoding process converts every 3 bytes of the image file into 4 Base64 characters. Here's the process at a high level:

  1. Read the file: The image file is read as raw binary data (an array of bytes).
  2. Group into 3-byte chunks: The binary data is divided into groups of 3 bytes (24 bits).
  3. Split into 6-bit parts: Each 24-bit chunk is split into four 6-bit values (6 bits each = 64 possible values).
  4. Map to Base64 alphabet: Each 6-bit value is mapped to a character in the Base64 table (A-Z, a-z, 0-9, +, /).
  5. Add padding: If the last chunk is incomplete, = padding is added to make it a full 4-character group.
  6. Prepend the data URI prefix: The MIME type and ;base64, are prepended to create the complete data URI.

The Base64 Image Converter handles all of this automatically. Simply drag an image onto the upload area or click to browse. The encoded data URI appears instantly in a copyable text area.

Decoding Base64 Back to Images

The decode process reverses the encoding steps. You paste a Base64 data URI (or the raw Base64 string), and the tool converts it back into a viewable image that you can download as a file.

The decode section of the tool accepts:

  • Full data URIs: data:image/png;base64,iVBOR...
  • Raw Base64 strings: iVBORw0KGgo... (the tool auto-detects and adds the proper prefix)

The decoded image is displayed as a preview, and you can download it by clicking the "Download Image" button. The tool attempts to restore the original file name and preserves the original quality since Base64 encoding is lossless.

When to Use (and Avoid) Base64 Images

Base64 embedding is a trade-off between HTTP requests and data size. Use this guide to decide:

ScenarioUse Base64?Reason
Small icons (< 10 KB)✓ GoodSaves an HTTP request, minimal size overhead
CSS background textures✓ GoodEsp. if used on many elements; eliminates extra requests
Email-embedded images✓ RequiredEmail clients block external images; inline data URIs work
Large photographs (> 100 KB)✗ Avoid33% size increase + blocks initial render
Images used once on a single page✓ ConsiderTrade-off depends on size; under 50 KB is usually fine
Images shared across many pages✗ AvoidCached external file is more efficient
API responses returning images✓ GoodJSON + Base64 avoids binary transport issues

Key Rule: If the image is under 10 KB, Base64 is almost always a win. If it's over 50 KB and used in a web page, a regular <img> tag with an external URL is usually better. Between 10–50 KB, test both approaches with your specific use case.

Practical Examples

Example 1: Inline SVG Icon in CSS

Convert an SVG icon to Base64 and use it as a CSS background:

.close-button {
  /* Before: separate SVG file (1 HTTP request) */
  /* After: embedded data URI (0 extra requests) */
  background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIj48bGluZSB4MT0iMTgiIHkxPSI2IiB4Mj0iNiIgeTI9IjE4Ii8+PGxpbmUgeDE9IjYiIHkxPSI2IiB4Mj0iMTgiIHkyPSIxOCIvPjwvc3ZnPg==");
  background-size: cover;
  width: 24px;
  height: 24px;
}

Example 2: Self-Contained HTML Email Signature

Email signatures with images must embed all assets inline because external images are blocked by most email clients:

<table>
  <tr>
    <td>
      <img src="data:image/png;base64,iVBORw0KGgoAAAANS..." 
           alt="Logo" width="80">
    </td>
    <td>
      Company Name<br>
      contact@example.com
    </td>
  </tr>
</table>

Example 3: Storing Images in LocalStorage

When building offline-capable web apps, you can encode user-uploaded images as Base64 and store them in localStorage or IndexedDB:

// Capture image from file input, encode, store
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function(e) {
  localStorage.setItem('user-avatar', e.target.result);
  // e.target.result is the full data URI
};
reader.readAsDataURL(file);

Base64 Best Practices

  • Always compress before encoding: Optimize the image first (reduce dimensions, increase JPEG compression) before converting to Base64. The encoding is lossless, but smaller input = smaller output.
  • Avoid Base64 for large images in HTML: A 200 KB image becomes ~270 KB of embedded text that blocks document parsing. Use lazy-loaded external images instead.
  • Use SVG directly when possible: For vector graphics, inline SVG markup is cleaner and more compressible than Base64-encoded SVG. Only use Base64 for SVGs when you must embed them in CSS url().
  • Consider WebP format: WebP images are typically 25–35% smaller than PNG or JPEG at equivalent quality. Convert to WebP first, then encode to Base64 for the smallest data URIs.
  • Use the Base64 Image Converter for one-off tasks: For build-time processing, consider tools like Webpack's url-loader or Vite's built-in asset handling which automatically inline small images as Base64.
  • Always verify decoded images: After decoding, check the preview to confirm the image rendered correctly. Corrupted Base64 strings produce broken images.

Ready to encode or decode your images?

Try Base64 Image Converter