Image to Base64 Converter

Upload any image and instantly get the Base64 encoded string. Copy as data URI, raw Base64, or HTML img tag.

Runs in your browser — images never leave your device
Drop your image here or click to upload
JPG, PNG, WebP, GIF, SVG, BMP, ICO · No size limit
Your uploaded image
Name:
Type:
Size:
Dimensions:
Your Base64 encoded string will appear here
Length: 0 characters
~0 KB encoded

You're just getting started

PixelPanda does way more than image editing. Create content that sells.

🧑‍🎨
AI Avatars
Create AI models of yourself
📸
Product Photos
Studio-quality in seconds
🎬
AI Videos
Talking head videos with lip sync
Try It — 200 Credits for $5

How It Works

1

Upload Your Image

Drop any image file — JPG, PNG, WebP, GIF, SVG, BMP, or ICO. No file size limit.

2

Instant Conversion

Your image is converted to Base64 right in your browser. Nothing is uploaded to any server.

3

Copy or Download

Copy as data URI, raw Base64, HTML img tag, or CSS background. Or download as a text file.

What Is Base64 Encoding?

Base64 converts binary files (like images) into plain text so you can embed them right in your code.

The concept is straightforward. Base64 takes the raw bytes of a file and turns them into a string of regular text characters -- letters, numbers, plus signs, slashes. A 64-character alphabet, hence the name. Every 3 bytes of binary input becomes 4 characters of text output, which means the encoded version is roughly 33% bigger than the original. That's the price you pay for being able to jam an image directly into an HTML file or a JSON payload without any binary data involved.

Fun fact: this whole scheme was originally invented for email. Early email systems could only deal with plain text, so attaching a photo meant encoding it as text first. These days, the main use case is web development -- embedding small images directly in HTML, CSS, or JavaScript so the browser skips the extra network request it'd normally need to fetch the file.

How Base64 Encoding Works

Here's how it works mechanically: the encoder grabs 3 bytes at a time (24 bits total), splits them into four 6-bit chunks, and maps each chunk to a character from the Base64 alphabet. If the input doesn't divide evenly by 3, you get padding characters (those `=` signs at the end) to fill things out.

Quick example: the text "Hi" is 2 bytes. The encoder splits those bits into three 6-bit groups that map to the characters S, G, and k. Since the input was only 2 bytes instead of 3, one padding character gets tacked on. Final result: "SGk=". Not exactly human-readable, but that's the point -- it's meant for machines to parse.

Data URIs: Embedding Images in Code

A data URI is how you actually use a Base64 image in a web page. The format looks like this: data:[mediatype];base64,[data]. For a PNG, that'd be something like data:image/png;base64,iVBORw0KGgo.... You can drop this anywhere you'd normally put an image URL -- in an img tag's src, a CSS background-image, a JavaScript Image object, wherever. The browser treats it just like a regular URL, except the image data is right there inline instead of being fetched from a server.

Why Convert Images to Base64?

There are a handful of situations where embedding a Base64 image actually makes more sense than linking to a file. Here are the main ones.

Reduce HTTP Requests

Every image on a page triggers a separate round trip to the server. Got 30 tiny icons? That's 30 HTTP requests for decoration alone. Embed them as Base64 in your HTML or CSS and all those requests disappear. For images under about 10KB, the saved network overhead more than makes up for the slightly larger file.

Email HTML Templates

Here's one that catches a lot of people off guard: most email clients block external images by default. Your beautifully designed email shows up with broken image icons until the reader clicks "display images." Nobody clicks that. Embed your logo and key icons as Base64 and they show up immediately -- the data's already in the HTML, no external fetch needed.

Single-File Applications

Building a browser extension? A self-contained HTML report? A widget that has to work with no server behind it? You can't reference external image files in any of those. Base64 lets you bake everything -- HTML, CSS, JavaScript, images -- into one file. Nothing external to break, nothing to host separately.

CSS Sprites & Stylesheets

Checkmark icons. Arrows. Loading spinners. Those tiny UI elements that show up on every page. They're perfect Base64 candidates -- usually under 2KB each, and inlining them in your CSS means they load with the stylesheet instead of triggering individual HTTP requests. The CSS file gets a bit bigger, but overall page load gets faster.

API Payloads & JSON

JSON can't handle binary data. Full stop. So when you need to send an image through a REST API, a webhook, or any text-based protocol, Base64 is how you get it in there. Most AI image APIs -- OpenAI, Replicate, Stability AI -- expect images as Base64 strings, and they send results back the same way.

Database Storage

Sometimes you just want to stick a thumbnail in a database row without spinning up S3 or configuring a file server. Base64 strings drop right into a text column. It's not the right move for large images, but for tiny avatars, icons, or thumbnails that logically belong alongside their data? It keeps things dead simple.

Image to Base64 Converter Features

Everything runs locally in your browser. Your images never touch a server.

100% Client-Side

Your images never leave your device. All conversion happens in the browser using the FileReader API.

Instant Conversion

Images are encoded to Base64 in milliseconds. No upload delay, no server processing, no waiting.

All Formats

Supports JPG, PNG, WebP, GIF, SVG, BMP, ICO, and any image format your browser supports.

Multiple Output Formats

Copy as data URI, raw Base64, HTML img tag, or CSS background-image — ready to paste into your code.

Unlimited & Free

No daily limits, no sign-up, no watermarks. Convert as many images as you need, forever free.

Works Everywhere

Runs on any device — desktop, tablet, or phone. No software or extensions needed, just a browser.

How to Use Base64 Images in Code

Got your Base64 string? Here's how to actually use it in real projects.

HTML Image Tag

Use the data URI directly in the src attribute of an img tag:

<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." alt="My image">

CSS Background Image

Embed the image as a CSS background using the url() function with a data URI:

.icon { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANS...'); background-size: contain; width: 24px; height: 24px; }

JavaScript Image Object

Create an Image object and set the source to the data URI:

const img = new Image(); img.src = 'data:image/png;base64,iVBORw0KGgoAAAANS...'; img.onload = () => document.body.appendChild(img);

React / JSX

Use the data URI in JSX just like a regular image URL:

const base64Image = 'data:image/png;base64,iVBORw0KGgoAAAANS...'; return <img src={base64Image} alt="My image" />;

JSON API Payload

Include the raw Base64 string (without the data URI prefix) in JSON:

{ "image": "iVBORw0KGgoAAAANS...", "filename": "photo.png", "content_type": "image/png" }

Base64 Encoding Size Impact

Base64 makes things about 33% bigger. Here's a practical guide to when it's worth it and when it's not.

Original Size Base64 Size Recommendation
< 2 KB ~2.7 KB Embed as Base64 — eliminates HTTP request overhead
2 - 10 KB ~2.7 - 13.3 KB Good candidate for Base64 — especially for CSS/email
10 - 50 KB ~13.3 - 66.7 KB Consider carefully — use for emails, avoid in CSS
50 - 200 KB ~66.7 - 266.7 KB Usually better as external file — too large for inline
> 200 KB > 266.7 KB Use external file — Base64 hurts performance at this size

The 33% increase is unavoidable -- it's baked into how the encoding works (3 bytes of binary become 4 bytes of text). For small stuff like icons and logos under 10KB, skipping the HTTP request usually makes up for the extra size. But once you're past 20-30KB, you're bloating your HTML or CSS with a giant string that can't be cached on its own. At that point, just serve the image as a normal file and let the browser cache it properly.

Best Practices for Base64 Images

A few rules of thumb so you don't accidentally tank your page performance.

Keep Base64 Images Small

Stick to images under 10KB. Once you go bigger, the encoded string starts bloating your HTML or CSS file in a way that actually hurts load times. The browser can't cache a Base64 image separately from the page, either. If it's over 10KB, just serve it as a regular file.

Optimize Before Encoding

Run your image through TinyPNG, ImageOptim, or convert it to WebP before you Base64-encode it. There's no point encoding a 50KB unoptimized PNG when you could compress it to 5KB first. Smaller source file = shorter Base64 string = less bloat in your code.

Use Data URIs in CSS for UI Icons

This is the sweet spot for Base64. Small icons that appear on every page -- checkmarks, arrows, close buttons, spinners. Embed them in your main CSS file, and they get cached along with the stylesheet. No extra HTTP requests, no flash of missing icons on first load.

Avoid Base64 for Responsive Images

You can't use srcset or sizes with a Base64 data URI, so responsive images are out. If you need different image sizes for different screen widths or pixel densities, serve external files with proper responsive markup instead.

Consider Gzip Compression

Here's a silver lining: Base64 strings compress surprisingly well with gzip or brotli because of the repetitive character patterns. So the actual transfer size over the wire is smaller than the raw string length suggests. That 33% overhead? It's partially offset by your server's compression. Not fully, but enough to take some of the sting out.

Frequently Asked Questions

Is my image uploaded to a server?
Nope, everything happens right in your browser. The JavaScript FileReader API handles the conversion locally -- your image never leaves your device. Nothing gets sent to any server. It's about as private as a tool can get.
Is there a file size limit?
No hard limit -- it'll convert images of any size. That said, if your image is over 5MB, the resulting Base64 string is going to be enormous and might cause performance issues if you try to embed it in HTML or CSS. For anything that large, you're better off serving it as an external file.
What image formats are supported?
Anything your browser can display: JPG, PNG, WebP, GIF (animated ones too), SVG, BMP, ICO, TIFF, and more. The Base64 output preserves the original format -- a PNG input gives you a PNG data URI, a JPG gives you a JPG data URI, and so on.
Why is the Base64 string larger than the original file?
That's just how the encoding works -- every 3 bytes of binary become 4 ASCII characters, so you get roughly a 33% size increase. It's the tradeoff for representing binary data as plain text. For small images (under 10KB), eliminating the HTTP request usually makes up for it. For bigger files, just serve them normally.
What is a data URI?
It's a way to embed content directly in a document instead of linking to an external file. The format looks like this: data:image/png;base64,iVBORw0KGgo... You can use it anywhere you'd normally put an image URL -- img src attributes, CSS url() values, JavaScript Image objects. The browser treats it like a regular URL, except the image data is right there inline.
Can I convert Base64 back to an image?
Absolutely -- Base64 is fully reversible, it's encoding, not encryption. Quickest way to check: paste the data URI into your browser's address bar and it'll display the image. In code, use atob() in JavaScript or base64.b64decode() in Python to get the binary data back.
Does it work with animated GIFs?
Yep. The whole GIF -- all animation frames -- gets Base64-encoded. The resulting data URI will play the full animation in HTML or CSS. Just keep in mind that animated GIFs tend to be large files, so the encoded string will be proportionally long.
Can I use Base64 images in emails?
This is actually one of the best use cases for it. Most email clients block external images by default (for security), so your email shows up with broken image icons. Embed your logo and key icons as Base64, and they display immediately. Just keep the encoded images under about 100KB for the best compatibility across email clients.
Is Base64 encoding secure?
Not at all -- and that's important to understand. Base64 is encoding, not encryption. Anyone can decode a Base64 string and see the original data. It's designed for making binary data portable across text-only channels, not for hiding anything. Don't use it as a security measure.
How many images can I convert?
As many as you want. Since everything runs in your browser with zero server involvement, there are no daily limits, no accounts, no caps. Convert 500 images today if you feel like it.
Does it work on mobile?
Works on any device with a browser -- iPhone, Android, iPad, laptop, desktop. Take a photo on your phone and convert it to Base64 right there, no app needed.
What's the difference between Raw Base64 and Data URI?
Raw Base64 is just the encoded string itself (e.g., iVBORw0KGgo...). A data URI includes the MIME type prefix (e.g., data:image/png;base64,iVBORw0KGgo...). Use data URIs for HTML/CSS/browser contexts. Use raw Base64 for API payloads, database storage, and programming contexts where the MIME type is specified separately.
When should I NOT use Base64 images?
Avoid Base64 for: large images (over 10-20KB) on web pages, responsive images that need srcset/sizes, images that change frequently (Base64 prevents independent caching), and performance-critical applications where every kilobyte matters. In these cases, serve images as external files with proper caching headers.
Can I use SVG files?
Yes, SVG files are fully supported. The converter will produce a data URI with the image/svg+xml MIME type. Note that for SVGs, you can also embed them directly as inline SVG code in HTML without Base64 encoding, which is often more efficient and allows CSS styling of SVG elements.
How does this compare to command-line tools?
Command-line tools like base64 (Unix/Mac), certutil (Windows), or Python's base64 module can also convert images to Base64. This web tool offers the same result with a simpler interface — no terminal commands to remember, instant preview, and multiple output formats (data URI, raw, HTML, CSS) ready to copy. Plus, your images stay local just like with CLI tools.
How do I convert base64 back to JPG or PNG?
To decode a base64 string back to an image: in a browser, paste the full data URI (data:image/png;base64,...) into the address bar to view it, then right-click and save. In Python, use base64.b64decode() to get the binary data and write it to a file. In JavaScript, create a Blob from the decoded data and use URL.createObjectURL() to generate a downloadable link.
How do I convert an image to base64 in Python?
Use the built-in base64 module: import base64, then with open('image.png', 'rb') as f: encoded = base64.b64encode(f.read()).decode('utf-8'). To create a data URI, prepend the MIME type: f'data:image/png;base64,{encoded}'. This is common in Flask and Django for embedding thumbnails in API responses.
How do I convert an image to base64 in JavaScript?
In the browser, use FileReader: reader.readAsDataURL(file) returns a data URI with the base64 string. In Node.js, use fs.readFileSync('image.png').toString('base64') to get the raw base64, then prepend 'data:image/png;base64,' for a data URI. The Canvas API can also export any canvas element as base64 using canvas.toDataURL().
Can I base64 encode an image from a URL?
Not directly with this tool since it runs in your browser and doesn't fetch external URLs. Download the image first, then upload it here. Programmatically, in Python use requests.get(url).content then base64.b64encode(). In Node.js, fetch the image, get the arrayBuffer, and convert to base64.
What is the base64 size limit for HTML or CSS?
There's no hard technical limit. Most modern browsers handle data URIs up to 2MB without issues. Legacy Internet Explorer had a 32KB limit. For performance though, keep base64 images under 10-20KB in CSS and under 50KB in HTML. Anything larger should be served as an external file for better caching and page load times.
How do I embed a base64 image in a Markdown file?
Standard Markdown supports data URIs: ![alt text](data:image/png;base64,iVBORw0KGgo...). Works on GitHub, GitLab, and most renderers. However, it makes the file huge and hard to read, so only practical for tiny images like badges or icons. For larger images, host them externally and reference the URL.
Is base64 or a URL better for web performance?
For images under 2-5KB (tiny icons, logos), base64 is better because it eliminates an HTTP request. For images over 10KB, external URLs are better because they can be cached independently, loaded in parallel, and don't bloat your HTML/CSS. The crossover point depends on your setup, but 5-10KB is a good rule of thumb.
Can I convert a screenshot to base64?
Yes. Screenshots are just image files (usually PNG on Mac/Windows, or JPG on some Android devices). Upload your screenshot here and it'll be base64-encoded like any other image. Useful for embedding in bug reports, documentation, API test payloads, or automated testing scripts.
How do I use base64 images in React Native?
React Native's Image component supports data URIs directly: <Image source={{uri: 'data:image/png;base64,iVBORw0KGgo...'}} />. Useful for bundling small images without an asset pipeline. For larger images, use require() or fetch from a remote URL for better memory management.
Can I convert multiple images to base64 at once?
This tool handles one image at a time. For batch conversion, use a script: in Python, loop through files with base64.b64encode(). In Bash: for f in *.png; do base64 "$f" > "$f.b64"; done. For a quick web approach, convert each image here one at a time.

Base64 Image Encoding in Python, JavaScript & PHP

Need to convert images to base64 programmatically? Here's the quick reference for every major language.

Python

Python's standard library makes base64 encoding straightforward. Read the file as binary, encode it, and decode the bytes to a UTF-8 string. This is the most common approach for Django, Flask, and FastAPI backends that need to embed images in API responses or database records.

import base64 with open("photo.jpg", "rb") as f: encoded = base64.b64encode(f.read()).decode("utf-8") data_uri = f"data:image/jpeg;base64,{encoded}"

JavaScript / Node.js

In the browser, the FileReader API handles conversion automatically. In Node.js, read the file into a Buffer and call .toString('base64'). Both environments support data URIs natively, so you can use the result directly in img tags, Canvas, or API requests.

// Node.js const fs = require('fs'); const base64 = fs.readFileSync('photo.jpg').toString('base64'); const dataUri = `data:image/jpeg;base64,${base64}`; // Browser (FileReader) const reader = new FileReader(); reader.onload = () => console.log(reader.result); // data URI reader.readAsDataURL(file);

PHP

PHP's base64_encode() function handles the conversion in a single call. Read the file with file_get_contents(), encode it, and build the data URI. This is commonly used in WordPress plugins, Laravel views, and email templates generated server-side.

$imageData = file_get_contents('photo.jpg'); $base64 = base64_encode($imageData); $dataUri = 'data:image/jpeg;base64,' . $base64;

cURL / Command Line

On macOS and Linux, the base64 command is built in. On Windows, use certutil. Pipe the output into your clipboard or a file for quick use in HTML, CSS, or API testing tools like Postman.

# macOS / Linux base64 -i photo.jpg | pbcopy # copies to clipboard # Windows certutil -encode photo.jpg output.b64

Convert Base64 Back to an Image

Base64 encoding is fully reversible. Here's how to decode a base64 string back to a JPG, PNG, or any image format.

Decode in Your Browser

The quickest way to see a base64 image: paste the full data URI (data:image/png;base64,iVBORw0KGgo...) directly into your browser's address bar and press Enter. The image displays immediately. Right-click and "Save As" to download it as a file. This works in Chrome, Firefox, Safari, and Edge with no tools needed.

Decode in Python

Python's base64.b64decode() reverses the encoding. Strip the data URI prefix first if present, then write the decoded bytes to a file with the appropriate extension.

import base64 # Strip data URI prefix if present b64_string = "iVBORw0KGgo..." # raw base64 image_bytes = base64.b64decode(b64_string) with open("output.png", "wb") as f: f.write(image_bytes)

Decode in JavaScript

In the browser, convert the base64 string to a Blob and create a downloadable link. In Node.js, use Buffer.from() to decode and write to disk.

// Browser — trigger download const b64 = "iVBORw0KGgo..."; const byteArray = Uint8Array.from(atob(b64), c => c.charCodeAt(0)); const blob = new Blob([byteArray], { type: "image/png" }); const url = URL.createObjectURL(blob); window.open(url); // Node.js fs.writeFileSync("output.png", Buffer.from(b64, "base64"));

When to Decode

Common scenarios where you need to go from base64 back to an image file: extracting images from API responses, saving email-embedded images, debugging data URIs in CSS or HTML, recovering images stored as base64 in databases, or converting Markdown-embedded images to separate files for better version control.

Related Free Tools

200 credits for $5

Go beyond editing — create content that sells

AI product photography, UGC videos, and custom avatars. Everything you need to scale your brand's content.

Try It — 200 Credits for $5
No subscription required