Image to Base64 Converter

Output format—
Dimensions—
Megapixels—
Size vs file—

How Image to Base64 Converter is calculated: Base64 text = 4 characters for every 3 bytes of the file, so the string is about 33% larger than the file

What is an image to base64 converter?

Base64 is a way of writing a file as plain text. Every three bytes of the file become four text characters, using only letters, digits, plus, slash, and equals. An image to base64 converter takes a picture file and turns it into that text — a long string you can paste into code, a document, or a data field where a file upload is not possible.

Developers use base64 images every day. A small icon can be embedded directly in a web page or a stylesheet as a data URL, so the page needs no separate image request. An email template can carry its images inside itself, so they display even when the mail client blocks remote images. An API can accept an image as a text field, which is far easier than handling a file upload.

This converter works entirely in your browser. When you choose a file, it is read on your own device and turned into base64 text with the FileReader built into the browser. Nothing is uploaded to any server, so your images stay private, and the tool works even on a slow connection once the page has loaded.

How base64 encoding works

A file is a sequence of bytes, and base64 rewrites those bytes in an alphabet of 64 text characters. Three bytes — 24 bits — are split into four groups of 6 bits, and each group becomes one character. That is why the output is always about a third larger than the input: four characters carry what three bytes used to, so the text is 4 divided by 3, or about 133%, of the file size.

The output comes in two forms. A raw base64 string is just the characters — nothing else. A data URL adds a prefix that says what the data is, for example data:image/png;base64, followed by the same characters. The prefix is what makes the string usable directly in a web page: paste it into an image tag or a stylesheet and the browser renders the picture from the text alone.

The conversion itself is exact and reversible. Base64 throws nothing away, so decoding the string gives back the original file byte for byte. That is also why the string is so long: a 300 KB JPEG becomes about 400 KB of text, because 300 times 4 divided by 3 is 400. The results box tells you the output is about 33% larger than the file, and the preview shows the exact character count once your file is loaded.

Data URL or raw base64: which output do you need?

Choose a data URL when the string goes straight into a web page, a stylesheet, or an image tag. The prefix tells the browser what format the image is and that the rest is base64, so it renders without any extra work from you. Most web uses — embedding a small icon, inlining a logo in an email template — want the data URL form.

Choose raw base64 when the string goes into a database field, an API request, or a JSON document. Those places usually store the prefix separately or do not want it at all, and a raw string is cleaner to handle in code. If you are pasting into a form that says 'paste base64 here', it almost always means the raw string, not the data URL.

If you pick the wrong one, the fix is easy: the two forms differ only by the prefix, so you can add or remove data:image/png;base64, by hand. Just make sure the prefix matches the real format — a JPEG with a PNG prefix will not render. Our base64 encoder decoder handles plain text the same way if you need to encode words rather than an image.

A worked example: a 300 KB photo becomes base64 text

Take a typical photo, 1920 by 1080 pixels, about 2.1 megapixels, saved as a JPEG of about 300 KB. That file holds 307,200 bytes. Base64 turns every 3 bytes into 4 characters, so the raw string is about 409,600 characters long — 300 KB times 4 divided by 3 is 400 KB of text. The data URL form adds a short prefix of about 23 characters, which is nothing next to 400,000.

Now try a smaller image. An 800 by 600 photo is 0.5 megapixels, and its uncompressed size is 1,440,000 bytes at 3 bytes per pixel, which is 1.37 MB. If that image were encoded from its raw pixels, the base64 string would be 1,920,000 characters — but in practice you encode the compressed JPEG file, which might be only 120 KB, so the real string is about 160 KB of text. The preview under the tool shows the exact count for your file, so you never have to guess.

The 33% rule is the number to remember. Whatever the file size, the base64 text is about a third larger. A 30 KB icon becomes about 40 KB of text, and a 3 MB photo becomes about 4 MB of text. That is why base64 suits small images and is a poor choice for large ones — the text grows fast, and so does the page that carries it.

Why convert an image to base64

The biggest reason is embedding. A small icon or logo embedded as a data URL travels inside the page itself, so the browser makes no extra request to fetch it. For a page with a handful of tiny icons, that can mean fewer requests and a faster first paint. Email templates benefit even more, because many mail clients block remote images but display embedded ones.

The second reason is transport. Some systems only accept text: a JSON API, a database text field, a configuration file, or a chat message. Base64 is how a binary file travels through a text-only channel without being damaged. Paste the string in, and the other end decodes it back to the exact original file.

The third reason is simplicity in code. A data URL can be dropped into an image tag, a stylesheet background, or a test fixture with no file handling at all. That makes it handy for prototypes, demos, and tests, where setting up file storage would be more work than the feature itself. Our image compressor is worth running first if the file is large, because a smaller file makes a much shorter string.

Image to base64 vs base64 to image: which direction?

These two tools are mirror images of each other. Image to base64 takes a file and gives you text. Base64 to image takes text and gives you back a file. If you have a picture and need a string to paste into code, you need this tool. If you have a long string and need to see what picture it holds, you need the other direction.

The round trip is exact: encode a file, decode the string, and you get the original file back byte for byte. That is useful for testing — encode a small image, copy the string, decode it elsewhere, and compare the files. If they match, the channel carried the text cleanly; if they do not, something in the middle changed the string, usually by wrapping lines or stripping characters.

One practical note: the two tools share a limit. Base64 text is about 33% larger than the file, so a 3 MB photo becomes about 4 MB of text, and pasting that into a chat message or a form is painful. Shrink the image first with our image resizer, or convert it to a smaller format with our image converter, and the string becomes far more manageable.

Common mistakes when converting images to base64

The most common mistake is encoding a huge photo. A 6 MB phone photo becomes about 8 MB of base64 text, which is far too long to paste anywhere and slows down any page that carries it. Base64 is for small images — icons, logos, thumbnails under 100 KB. For anything bigger, link to the file instead of embedding it.

The second mistake is mixing up the two output forms. Pasting a raw string into a web page without the data URL prefix shows nothing, because the browser does not know the text is an image. Pasting a data URL into an API that expects raw base64 can fail, because the prefix is not valid base64. Pick the form the destination asks for, and check the prefix matches the real format.

The third mistake is breaking the string. Base64 must be copied whole — a missing character at the end, a line break in the middle, or a space added by a word processor all corrupt it, and the decoded image fails. Always copy with the Copy button, which takes the exact string, rather than selecting the text by hand. And never encode your only copy of a photo and delete the file: keep the original.

How to use this image to base64 converter

First, choose an image with the file picker. JPEG, PNG, WebP, GIF, and SVG files work; other formats are rejected with a clear message. As soon as the file loads, its real width and height fill in automatically above, and the base64 text appears below in a text box with a Copy button.

Next, pick the output form. Choose Data URL if the string goes into a web page or a stylesheet, or Raw Base64 if it goes into a database, an API, or a JSON document. The results box updates live, showing the output form, the dimensions, the megapixel count, and the reminder that the text is about 33% larger than the file.

Finally, copy the string with the Copy button. The preview shows the exact character count and how much larger the text is than the file, so you can see the real cost before pasting it anywhere. Your image never leaves your device: the whole process runs in your browser, and closing the page deletes everything.

Frequently Asked Questions

About 33% larger. Every 3 bytes of the file become 4 characters of text, so a 300 KB JPEG becomes about 400 KB of base64 text. That is why base64 suits small images like icons and logos, and is a poor choice for large photos — the text grows fast.

A data URL adds a prefix like data:image/png;base64, before the same characters, which tells a browser the text is an image and what format it is. Raw base64 is just the characters, with no prefix. Use a data URL for web pages and stylesheets, and raw base64 for APIs, databases, and JSON.

Yes, exactly. Base64 throws nothing away, so decoding the string gives back the original file byte for byte. That is also why a broken string fails: a missing character at the end or a space in the middle corrupts the data, so always copy with the Copy button instead of selecting by hand.

No. The file is read on your own device and turned into base64 text by the browser itself. Nothing is sent to any server, so your images stay private, and the tool works even on a slow connection once the page has loaded.

More free tools

More calculators and utilities from Sortrun — free, no sign-up.