What Is Base64 Image Encoding and How Do You Use It?

By Prestofiles Team · · 2 min read

Base64 turns a picture into plain text so it can live inside HTML, CSS, JSON or an email. Learn what it is, when it helps and when it hurts.

Base64 is a way to write binary data, such as a picture, using only normal letters, numbers and a few symbols. The result is a long piece of text that can be pasted anywhere text is allowed.

Why people use it

  • Put a small image directly inside HTML or CSS, so the page needs one request less.
  • Send an image inside a JSON message to an API.
  • Store a tiny icon or signature in a database text field.
  • Embed pictures in email templates.

What a data URI looks like

An image in HTML can be written like this: <img src="data:image/png;base64,iVBORw0KGgo...">. Everything after the comma is the encoded picture, and image/png tells the browser what type it is.

Encode an image

  1. Open the Base64 Image Converter.
  2. Choose Image to Base64.
  3. Select your picture.
  4. Press Copy and paste the text where you need it.

When not to use it

Base64 makes data about one third larger than the original file. For big photos this is a bad trade: the page gets heavier and the browser cannot cache the picture separately. Use it for small images, usually under a few KB. For large pictures, compress them and link to the file normally.

Next

Need the reverse? Read how to decode Base64 to an image.

Try it now: Base64 Image Encoder / Decoder Encode an image to Base64 text, or decode it back to a file. Open Base64 Image Encoder / Decoder
Ad space (shows only on your local machine)

Share your feedback

Tell us what you think, or what tool we should build next. We read every message.

What do you want to send?
How would you rate Prestofiles? (optional)
0 / 2000