How to Convert an Image to Base64 (Data URL)
By Rui Barreira · Last updated: 12 June 2026
You can convert any image to a Base64 data URL entirely in your browser using brevio Base64 Image Encoder — the FileReader API reads the image locally and produces the encoded string. The image never leaves your device.
Base64 encoding is a standard way to represent binary data (like image bytes) as a text string. For images, the result is a "data URL" — a self-contained string that can be used directly as an image source in HTML, CSS, or JSON, without a separate file request.
What Is Base64 and When Do You Need It?
Base64 is an encoding scheme that converts binary data to a text representation using 64 printable ASCII characters (A–Z, a–z, 0–9, +, /). Every 3 bytes of binary data become 4 base64 characters. A data URL combines the base64 string with a MIME type prefix so browsers know how to interpret it.
Common use cases for base64 image encoding:
- Inline images in HTML emails: Email clients often block external image requests for privacy. Embedding images as data URLs bypasses this restriction — the image is part of the email payload.
- Single-file HTML pages: When distributing a self-contained HTML file with no accompanying image files, embed small images as data URLs so the HTML file works standalone.
- CSS backgrounds: Small icons, patterns, or textures used as CSS background images can be embedded as data URLs to eliminate an extra HTTP request.
- JSON API payloads: APIs that accept image uploads via JSON (rather than multipart form) often expect images as base64 strings.
- SVG icons in JavaScript: Embed icons directly in JS/TS source files as data URL strings for use in canvas drawing or dynamic image creation.
How to Convert an Image to Base64
- Open brevio Base64 Image Encoder. No account, no installation required.
- Drop your image onto the drop zone, or click the drop zone to open a file picker. Supported formats: PNG, JPG, SVG, WebP, GIF.
- The tool encodes it immediately using the FileReader API. You will see a preview thumbnail, the MIME type, and the estimated base64 size.
- Copy the Data URL (the full string including the
data:image/...;base64,prefix) for use in HTMLsrc=attributes or CSSurl()values. - Or copy the raw Base64 string (without the prefix) for use in JSON API payloads or any context where you provide the MIME type separately.
How to Verify No Data Is Transmitted
- Open DevTools. Press F12 on Windows/Linux or ⌘⌥I on Mac.
- Go to the Network tab. Filter to Fetch/XHR requests.
- Drop your image onto the tool.
- Observe the Network tab. You will see zero outbound requests. The FileReader API reads the file into browser memory — it does not make a network request. This is particularly important if you are encoding logos, icons, or images that are not yet publicly released.
Understanding the Data URL Format
A data URL has this structure:
data:[MIME type];base64,[base64-encoded data]For example, a small PNG icon becomes:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwADhQGAWjR9awAAAABJRU5ErkJggg==The MIME type (image/png) tells the browser how to decode the bytes. The base64 string after the comma is the encoded image data.
How to Use Base64 Images in HTML and CSS
<!-- HTML img tag --><img src="data:image/png;base64,..." alt="Icon" width="32" height="32" />/* CSS background */.icon { background-image: url("data:image/png;base64,..."); }// JavaScript canvasconst img = new Image()
img.src = "data:image/png;base64,..."
img.onload = () => ctx.drawImage(img, 0, 0)Base64 Size Overhead
Base64 encoding adds approximately 33% overhead compared to the original file size. This is a fundamental property of the encoding scheme — every 3 bytes of binary data become 4 base64 characters. Practical implications:
| Original File Size | Base64 String Size | HTTP Overhead |
|---|---|---|
| 1 KB | ~1.4 KB | Negligible — save one HTTP request |
| 5 KB | ~6.8 KB | Break-even — no clear benefit either way |
| 20 KB | ~27 KB | Net negative — external file loads faster over HTTP/2 |
| 100 KB | ~137 KB | Significant negative — avoid base64 for images this large |
Base64 is best suited for images under 5KB. Above that, the size overhead outweighs the benefit of saving an HTTP request — modern HTTP/2 multiplexing makes multiple small requests cheap.
Comparison Table
| Tool | Upload to Server? | Account Required? | Cost | Output |
|---|---|---|---|---|
| brevio Base64 Image Encoder | No — FileReader API, fully local | No | Free forever | Data URL + raw base64 |
| base64encode.net | Yes — file uploaded to server | No | Free (ad-supported) | Base64 string |
| ezgif.com | Yes — file uploaded to server | No | Free (ad-supported) | Data URL |
| Browser DevTools console | No — local | No | Free | Data URL (via FileReader API script) |
Browser Console Alternative
You can encode any image to base64 directly in the browser DevTools console with this script:
const input = document.createElement('input')
input.type = 'file'
input.accept = 'image/*'
input.onchange = e => {
const reader = new FileReader()
reader.onload = () => console.log(reader.result)
reader.readAsDataURL(e.target.files[0])
}
input.click()Open DevTools → Console, paste the code, press Enter, and select your image. The data URL is logged to the console.
Frequently Asked Questions
What is the difference between a data URL and a regular image URL?
A regular image URL points to an external resource that the browser fetches over the network (e.g. https://example.com/logo.png). A data URL embeds the image data directly in the document — the browser reads it from memory rather than making a network request. Data URLs are self-contained but larger; regular URLs are smaller but require a network request.
Do data URLs work in all browsers?
Yes. Data URLs have been supported in all browsers for over a decade. They work in Chrome, Firefox, Safari, Edge, and mobile browsers. There are no compatibility concerns for modern web use.
Does converting an image to base64 upload it to a server?
Not with brevio. The FileReader API reads the image into browser memory entirely on your device. Verify with DevTools → Network tab: drop your image and confirm no outbound requests fire during encoding. Tools that use server-side conversion (base64encode.net, ezgif.com) do upload your file.
Can I decode a base64 string back to an image?
Yes — paste the data URL into an img src attribute and the browser renders it. To download it as a file, create an anchor tag with the data URL as the href and the download attribute set to a filename. For a full decode interface, use brevio's Base64 text tool which handles encode/decode in both directions for text content.
Is base64 a form of encryption?
No. Base64 is encoding, not encryption. Anyone who has the base64 string can trivially decode it back to the original image. If you need to protect image data, use encryption (AES-256) — base64 alone provides no security. It is simply a way to represent binary data as text.
Frequently Asked Questions
- What is a base64 data URL?
- A data URL encodes binary file data as a text string using base64 encoding, prefixed with the MIME type. Format: data:image/png;base64,<base64string>. You can use this directly as the src attribute of an img tag or as a CSS background-image url() value — no separate image file needed.
- Does converting an image to base64 upload it to a server?
- No. The FileReader API reads the image into browser memory locally. No network request is made during encoding. Verify with DevTools → Network tab: drop your image and confirm no outbound requests fire.
- How much larger does an image become in base64?
- Base64 encoding adds approximately 33% overhead. A 100KB PNG becomes roughly 133KB as a base64 string. This is why inline base64 is best suited for small images (icons, logos under 10KB). Large images are better served as separate files.
- When should I use a data URL instead of a file path?
- Data URLs are useful for: small inline icons in single-file HTML apps, JSON API payloads that include image thumbnails, email HTML where external image hosting is not available, and CSS where you want to avoid an extra HTTP request for a small background image.
- How do I use the base64 string in HTML and CSS?
- In HTML: <img src="data:image/png;base64,..." />. In CSS: background-image: url("data:image/png;base64,..."). In both cases, use the full data URL (including the data: prefix and MIME type), not the raw base64 string alone.