Maaz Zindani

Loading the index…

↑↓ move↵ openesc close3993 pages

Free tool · Image tools

Image to Base64

Choose an image and get its Base64 text as a data URL, raw Base64, an HTML img tag or a CSS background, ready to copy. The file is read in your browser and never uploaded.

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

Any image: JPG, PNG, WebP, GIF, SVG or ICO, up to 10 MB. It stays on your device.

Show me
Example result: a 35-byte GIF

48 characters35 B became 48 characters of Base64, 37.1% longer.

data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=

Paste into a browser address bar, an image src or a CSS url().

  • image/gif
  • +37.1% longer than the file
File size
35 B
Base64 length
48 characters
Data URL length
70 characters
Type
image/gif

Choose an image to encode your own.

How to use the Image to Base64

  1. Choose an image under Image: JPG, PNG, WebP, GIF, SVG or ICO, up to 10 MB.
  2. Under Show me pick Data URL, Base64 only, HTML img tag or CSS background. For the img tag you can type Alt text.
  3. Press Copy, or Download .txt for long output.
  4. Check Base64 length and File size, and read the note on whether this image is small enough to inline.

How do I convert an image to a Base64 string?

Base64 writes any bytes as plain text made of 64 safe characters: A to Z, a to z, 0 to 9, plus and slash, with = as padding. The tool reads your file, takes its bytes three at a time, and writes each group as four characters. Nothing about the picture changes: Base64 is just a way of carrying the same bytes in a place that only accepts text, such as HTML, CSS, JSON or an email.

Worked example: the sample on this page is a 35-byte GIF. Its Base64 is 48 characters long: R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=. With the prefix that makes it a data URL, the whole string is 70 characters: data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=. A 2.2 KB test PNG gives 2,952 characters of Base64 and 2,974 as a data URL.

The output is only text. The page never runs it, and your own text, such as the alt text, is inserted with its quotes and angle brackets escaped so it cannot break the tag.

How do I use a Base64 image in HTML or CSS?

Pick the form you need. A data URL is data:image/gif;base64, followed by the Base64: it can go anywhere a normal image address can go. The HTML img tag wraps it for you: <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" alt="A pixel">. The CSS background form gives a declaration you can paste into a rule: background-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=");. Base64 only gives the bare text, for an API, a JSON field or a database column.

Two details save time. Inside CSS, the data URL is wrapped in double quotes in url("..."), which is the safest form because the Base64 text itself never contains a quote. And because the string is long, keep it on one line or in a separate stylesheet: a string that is split across lines in the wrong place breaks the image, and the page shows only the start and the end of long output so the box stays readable while Copy and Download still hand you every character. SVG files are text already, but a data URL with Base64 still works for them and avoids having to escape characters.

The right MIME type goes into the data URL automatically. It is taken from the real first bytes of the file, so a PNG that has been renamed .jpg still gets image/png. SVG files get image/svg+xml.

To go the other way, from Base64 text back to a file, a Base64 decoder does that; see the Base64 decode tool. To make the image smaller before you encode it, use compress image first, because every byte you remove shrinks the text too.

Why is the Base64 string longer than the file, and when should I not use it?

Every 3 bytes become 4 characters, so the text is about one third longer than the file, plus up to two = characters of padding. The formula is 4 × ceil(bytes ÷ 3). 35 bytes become 48 characters, and 1,000 bytes become 1,336, which is 33.6% more. For small files the padding makes the overhead look larger, and for large ones it settles at 33.3%. The table runs the formula for common file sizes.

Base64 length for a file of each size (1 KB = 1,024 bytes)
File sizeBase64 charactersLonger by
1 KB1,36833.6%
10 KB13,65633.4%
50 KB68,26833.3%
100 KB136,53633.3%
500 KB682,66833.3%
1 MB1,398,10433.3%

The extra length is not the only cost. An image inside a data URL cannot be cached on its own: it is downloaded again whenever the page or stylesheet that holds it is downloaded, and it makes that file bigger and slower to parse. The page shows a note when the image is over 50 KB, which is our own rule of thumb, not a standard. A separate image file is usually better for photos and anything large. A data URL earns its place for a tiny icon or placeholder, where saving one request matters more than the third of extra text.

Use Base64 to carry an image in a place that only takes text. Do not use it to hide or protect a picture: anyone can decode it in a second. Everything here runs in your browser, so the image is not sent anywhere while you work.

Use it with

Questions

How do I convert an image to a Base64 string?

Choose the file and copy the output. The bytes are grouped in threes and each group is written as four characters. A 35-byte GIF becomes 48 characters.

How do I use a Base64 image in HTML or CSS?

Choose HTML img tag to get an img element with the data URL as its src, or CSS background to get a background-image declaration with url("data:...").

How do I convert Base64 back to an image?

Use a Base64 decoder and save the result with the right file extension. The Base64 decode tool on this site decodes Base64 text.

Why is the Base64 string longer than the file?

Base64 writes 3 bytes as 4 characters, so the text is about 33% longer. A 1,000 byte file gives 1336 characters.

When should I not use Base64 images?

For large images. A data URL cannot be cached separately and makes the page or stylesheet bigger. Use it for small icons and placeholders only.

Is my image uploaded?

No. The file is read and encoded in your browser and nothing is sent anywhere.

How this page was made: the tool's results are computed in your browser by the code on this page; the explanations were drafted with AI help and checked against the tool's own output.