Skip to content
Encoding2026-05-216 min read

Online Image to Base64 Converter: Encode Images to Text Strings

What Is Base64 Encoding

Base64 is a method for converting binary data to ASCII text. It uses 64 printable characters (A-Z, a-z, 0-9, +, /) to represent any binary data. You can use our Image to Base64 converter to turn any image into an embeddable data URI right away.

Encoding Principle

Original data (image): 2 bytes binary
    ↓ Base64 encoding
Base64 text: ~4 bytes ASCII text

Base64 encoded data is approximately 133% of the original (about 1/3 increase).

Why You Need Image to Base64

  1. Inline images: Embed small images directly in HTML/CSS to reduce HTTP requests
  2. Data URI: Use data:image/png;base64,... in HTML to inline images
  3. JSON transport: Send image data via APIs as Base64 strings
  4. Email attachments: Transfer binary files in email systems
  5. Database storage: Some databases lack binary types, use text storage
  6. Icons beyond SVG: Inline small icons to avoid extra requests

Base64 in Frontend Development

Data URI Inline Images

<!-- Traditional: requires HTTP request -->
<img src="/images/logo.png" alt="Logo">

<!-- Base64 inline: zero extra requests -->
<img src="data:image/png;base64,iVBORw0KGgo..." alt="Logo">

CSS Inline Background

/* Traditional */
.logo { background-image: url('/images/logo.png'); }

/* Base64 inline */
.logo {
  background-image: url('data:image/png;base64,iVBORw0KGgo...');
}

Pros and Cons of Inlining

ProsCons
Reduces HTTP requestsImage size increases ~33%
Good for small icons (<5KB)Cannot be browser-cached
No CORS issuesIncreases HTML/CSS file size
Good for email HTMLNot suitable for large images

How to Use an Online Tool

Using ToolVault's Image to Base64 Tool:

  1. Drag-and-drop, click to upload, or paste from the clipboard
  2. Supports common formats such as PNG, JPG, GIF, WebP, and SVG (when the browser reports an image MIME)
  3. Switch output chips: Data URI, pure Base64, HTML img, CSS url(), Markdown
  4. For HTML img and Markdown chips, fill Alt text so the pasted snippet is accessible out of the box (quotes and Markdown brackets are escaped for you)
  5. Check the size hint (original → encoded inflation %). Files over about 100KB show a soft warning — compress with the Image Compressor first, or keep a normal URL
  6. Copy, download a .b64.txt of the current chip, or clear and try another file; reverse with Base64 to Image

Image to Base64 in Code

JavaScript (Browser)

// Using FileReader
function imageToBase64(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.onload = () => resolve(reader.result);
    reader.onerror = reject;
    reader.readAsDataURL(file);
  });
}

// Usage
const base64 = await imageToBase64(imageFile);
console.log(base64); // data:image/png;base64,iVBORw0KGgo...

Node.js

const fs = require('fs');

function imageToBase64(filePath) {
  const data = fs.readFileSync(filePath);
  const base64 = data.toString('base64');
  const ext = filePath.split('.').pop();
  const mime = { png: 'image/png', jpg: 'image/jpeg', gif: 'image/gif' };
  return `data:${mime[ext]};base64,${base64}`;
}

Practical guidance

When to Use Base64?

  • Small icons (under 5KB)
  • Decorative images that rarely change
  • Images in emails where external loads are blocked
  • Tiny critical-path assets where an extra request still hurts

When NOT to Use Base64?

  • Large images (over ~10KB, and almost always over ~100KB)
  • Images that need independent browser caching
  • Images needing shareable URLs or CDN purge control
  • Frequently updated assets (every change rebakes the HTML/CSS/JS that embeds them)

Data URUs in CSS and HTML: where they pay and where they backfire

Inlining small images as base64 data URIs eliminates a request — good for critical-path assets under ~2-4KB (icons, tiny logos) where the request overhead dominates. Above that threshold the trade reverses: base64 inflates payload by 33%, blocks the HTML/CSS document it lives in (an external image loads in parallel), and defeats browser caching (the image re-downloads with every HTML fetch unless the document itself is cached). The modern answer for most former-inlining cases is HTTP/2 multiplexing (request overhead largely gone) plus proper cache headers. Reserve data URIs for genuinely tiny, per-render-variable images (charts generated this request, one-time email embeds where external references are blocked anyway).

Email: the one place base64 images are mandatory (and still unreliable)

HTML email clients block external images by default (privacy), so inline data URIs are the only images that render without user action — yet Outlook's Word-based renderer mangles large data URIs, Gmail clips messages over ~102KB, and some corporate gateways strip them entirely. The working pattern: keep inline images under 20-30KB after compression, provide alt text that survives stripping, and link to a web version. Email is also where image format matters most conservatively: PNG/JPEG universally decode, WebP/AVIF support in email clients is still a lottery.

The size inflation, quantified

Base64 encodes 3 bytes into 4 characters: exactly +33.3% on the image bytes, plus the data URI prefix overhead. A 150KB JPEG becomes ~200KB of text. That inflation flows everywhere the string goes: your HTML document weight, your JS bundle if the string is a constant, your database row if stored. The mitigation that matters: compress the image first (our image compressor before base64 conversion is the right order — a 60% WebP compression followed by base64 beats base64-then-nothing by more than the inflation costs), and consider whether the use case accepts a modern format that shrinks the source below the inflation line.

Choosing an output shape

ChipTypical paste target
Data URIimg src, some config fields
Pure Base64JSON fields that want payload only
HTML imgDrop a full tag into a static page (set alt text in the tool)
CSS url()background-image
MarkdownREADME, issues, docs sites (alt becomes the ![…] label)

The tool page surfaces the inflation percentage so you can decide compress-first vs inline-as-is. Download is useful when the string is too large for a comfortable clipboard paste into a terminal or ticket.

Accessibility note for img and Markdown chips

Empty alt="" is correct for purely decorative images. Meaningful icons and logos need a short phrase (“Company logo”, “Status: ok”). The converter keeps that field next to the HTML/Markdown chips so you do not discover missing alt text only after a accessibility audit.

FAQ

Can Base64 Be Reversed Back to an Image?

Yes. Base64 is lossless — any Base64 encoder/decoder can reverse it. Decode with atob() to get binary data, then write to a file.

Why Does Base64 Make Images ~33% Larger?

Base64 represents 8 bits of data using 6 bits, causing ~1/3 size increase. This is an inherent cost of the encoding method.

Should Small Images Use Base64 or References?

Use Base64 for icons under 5KB to reduce HTTP requests. Use traditional references for images over 10KB, as the size increase offsets request savings.

Triage notes

The data-URI tradeoff section pins its thresholds to reality: under 2–4 KB on the critical path, request overhead dominates and inlining pays; beyond that the scales tip — 33% inflation, a blocked document, and browser caching forfeited. With HTTP/2 multiplexing eliminating most request overhead, most classic data-URI use cases have been superseded by external links with proper cache headers. The email section's heading carries its own verdict — the one context where Base64 is mandatory, and still unreliable: Outlook's Word renderer mangles large URIs, Gmail clips messages above roughly 102 KB, and some gateways strip them entirely; the survivable pattern is compressing down to 20–30 KB with proper alt text. The output chips distinguish five paste-target forms because correct usage depends on whether the payload needs the MIME prefix.


Provided by ToolVault. Related tools: Image to Base64, Base64 to Image, Image Compressor. More tools on the homepage.