IMAGE TOOL

Image to Base64 Converter

Upload an image to get a Base64 data URI you can paste directly into HTML or CSS.

About this tool

This converter reads an image file from your device and turns it into a data URI: a single line of text that contains the whole image and can be pasted anywhere an image URL is expected. It uses the browser's FileReader API, so the file never leaves your computer. The preview shown above the output is drawn from the generated data URI itself, which is a quick check that the string is complete.

How to use the Image to Base64 Converter

  1. Choose an image file from your device.
  2. Preview the image and the generated data URI below it.
  3. Copy the data URI and paste it directly into an src attribute or CSS background-image property.

What a data URI looks like

The output follows the data: URL format documented on MDN: data:[media type][;base64],[data]. For a PNG it begins data:image/png;base64, followed by the encoded bytes. The media type comes from the file type your browser reports, so a JPEG gives image/jpeg, a WebP image/webp and an SVG image/svg+xml. The first characters after the comma also give the format away, because every file of a given type starts with the same signature bytes: PNG data begins iVBORw0KGgo, JPEG begins /9j/ and GIF begins R0lGOD.

Why Base64 makes files about a third larger

Base64, defined in RFC 4648, reads a file three bytes (24 bits) at a time and writes each group as four characters, each carrying 6 bits using an alphabet of 64 letters, digits, + and /. Four characters for every three bytes is a 4 ÷ 3 ratio, so the encoded text is about 33% larger than the file. When the byte count isn't a multiple of three, the final group is padded with one or two = signs, which is why small files come out slightly more than a third bigger. The exact length of the Base64 part is 4 × ⌈bytes ÷ 3⌉ characters, and the data:image/png;base64, prefix adds another 22.

Worked example

A 24×24 PNG clock icon saved at 199 bytes encodes to 268 Base64 characters: 199 ÷ 3 rounds up to 67 groups, and 67 × 4 = 268. The last group holds a single byte, so the string ends in ==. With the prefix, the complete data URI is 290 characters. You can use it in HTML:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAY…" width="24" height="24" alt="Clock">

or in CSS:

.icon-clock {
  background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAY…");
}

At the other end of the scale, a 200 KB (204,800-byte) photo becomes 273,068 characters — about 267 KB of text added straight into your HTML or CSS.

When inlining helps, and when it hurts

A data URI saves the browser a separate request for the image. That was a bigger win under HTTP/1.1, when browsers opened only a handful of connections per site; with HTTP/2 and HTTP/3, small requests are cheap, so today the benefit is often convenience — one self-contained file — as much as speed. The costs are worth weighing:

Common use cases

Tips and limits

To encode or decode plain text rather than an image file — or to turn a Base64 string back into readable text — use the Base64 Encoder & Decoder.

Base64 image size chart

The length of the Base64 text is always 4 × ⌈bytes ÷ 3⌉ characters, so you can work out the size of a data URI before you convert anything. The chart below uses 1 KB = 1,024 bytes and adds the 22-character data:image/png;base64, prefix in the last column. For a JPEG the prefix is data:image/jpeg;base64,, one character longer.

Image fileBytesBase64 charactersPNG data URI length
1 KB1,0241,3681,390
5 KB5,1206,8286,850
10 KB10,24013,65613,678
20 KB20,48027,30827,330
50 KB51,20068,26868,290
100 KB102,400136,536136,558
500 KB512,000682,668682,690
1 MB1,048,5761,398,1041,398,126

Each character of the output is one byte of ASCII text, so the right-hand column is also roughly how many bytes the image adds to your HTML, CSS or JSON before compression.

Using the Base64 part without the prefix

Many APIs and JSON fields ask for "the Base64 of the image", meaning only the encoded data. That is everything after the first comma of the data URI. For example, a field might need "image": "iVBORw0KGgo…" rather than the full data:image/png;base64,iVBORw0KGgo… string. Going the other way, if a service hands you raw Base64 and you want to show it in a page, put the matching prefix in front of it. Check the API documentation, because sending the prefix to a field that expects raw data is a common cause of "invalid Base64" errors.

Standard Base64 vs Base64url

RFC 4648 defines two alphabets. Standard Base64, which this tool produces, uses + and / and pads with =. The "URL and filename safe" variant, Base64url, swaps those two characters for - and _ so the text can sit in a URL or file name. JSON Web Tokens use Base64url, which you can see in the JWT Decoder. If you have to pass a standard data URI inside a query string, percent-encode it first with the URL Encoder, because +, / and = have special meanings there.

If the image does not show up

Frequently asked questions

How large can the image be before the data URI becomes impractical?

Base64 encoding increases size by roughly 33% over the original file, so it's best suited to small images like icons, logos, or UI sprites — a few KB at most. Large photos are better referenced as normal image files.

Does the data URI include the image format?

Yes — the output starts with a prefix like data:image/png;base64, or data:image/jpeg;base64, that tells the browser how to decode the data that follows.

Is my image uploaded to a server during conversion?

No — the conversion uses the browser's FileReader API entirely locally. The image never leaves your device.

Why is the output more than 33% larger than my file?

Base64 writes every 3 bytes as 4 characters, which is exactly a third more, but when the file size isn't a multiple of three the last group is padded with = signs, and the data:image/…;base64, prefix adds a couple of dozen characters. On a tiny icon those extras push the total noticeably above 33%; on large files it settles at just over a third.

Does converting an image to Base64 reduce its quality?

No. Base64 is a lossless way of writing the same bytes as text, so the image decoded from the data URI is identical to your original file, pixel for pixel. The only thing that changes is size: the text version is about a third larger than the file.

Is Base64 a form of encryption?

No. Base64 is an encoding defined in RFC 4648 with a public alphabet and no key, so anyone who has the string can turn it back into the original image. Do not rely on it to hide or protect an image. It only makes binary data safe to carry in text.

How do I turn a Base64 string back into an image file?

Make sure the string starts with the correct data:image prefix, then use it as the src of an img tag in a local HTML file and open that file in your browser. The image appears, and you can save it with right-click, Save image as.