Base64 Encoding Images in Emails: A Complete Guide

If you've ever looked at the HTML source code of an email and seen a long string of seemingly random characters after "data:image", you've encountered base64 encoding. But what exactly is it, and should you be using it in your email campaigns?

In this guide, we'll break down everything you need to know about base64 encoding images in emails, including when to use it and when to avoid it.

What is Base64 Encoding?

Base64 is a method of encoding binary data (like images) into ASCII text characters. This allows images to be embedded directly into HTML and CSS files as text strings, rather than being referenced as external files.

When you base64 encode an image, it converts the image file into a long string of letters, numbers, and symbols that looks something like this:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA...

This encoded string can be used directly in an <img> tag's src attribute or in CSS as a background image.

How Base64 Encoding Works in Emails

In email marketing, base64 encoding allows you to embed images directly into the email's HTML rather than hosting them on a server and linking to them.

Here's a comparison:

Traditional image embedding: html <img src="https://yourdomain.com/images/logo.png" alt="Logo">

Base64 encoded image: html <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA..." alt="Logo">

With base64 encoding, the entire image is contained within the HTML of the email itself.

Pros of Base64 Encoding Images in Emails

1. Images Can't Be Blocked by Default

Many email clients block external images by default for privacy and security reasons. With base64 encoded images, the image is part of the email itself, so it displays immediately without requiring the recipient to "download images."

2. No External Server Required

You don't need to host images on a web server or CDN. Everything is self-contained within the email, which can simplify deployment and eliminate broken image links.

3. Works Offline

Since the image data is embedded in the email, recipients can view the images even without an internet connection (as long as they've downloaded the email).

4. Single HTTP Request

The email client doesn't need to make additional HTTP requests to fetch images, which can marginally improve loading speed in some cases.

Cons of Base64 Encoding Images in Emails

1. Significantly Larger Email Size

Base64 encoding increases the file size of your images by approximately 33%. A 100KB image becomes 133KB when encoded. This bloats your email size, which can:

  • Cause emails to be flagged as spam
  • Take longer to load on slow connections
  • Use more of the recipient's data allowance on mobile
  • Hit email size limits imposed by some email clients

2. No Email Tracking

One of the biggest drawbacks is that you lose the ability to track email opens. Most email tracking works by embedding a tiny, unique image (tracking pixel) in each email. When the recipient's email client downloads that image from your server, it registers as an "open."

With base64 encoded images, there's no external request made, so no tracking data is captured.

3. Poor Email Client Support

While support has improved, some email clients still handle base64 images poorly or don't support them at all:

  • Outlook (desktop versions) has historically had issues with base64 images
  • Gmail clips messages over 102KB, and base64 encoding can quickly push you over this limit
  • Some mobile email clients may struggle with large embedded images

4. Cannot Update Images

Once the email is sent, the base64 encoded image is permanent. If you need to update an image (fix a typo, change pricing, etc.), you can't do it. With externally hosted images, you can swap out the image file and all emails will show the updated version.

5. Spam Filter Concerns

Large emails with heavily encoded content can trigger spam filters. The unusual encoding patterns may look suspicious to some filtering systems.

When Should You Use Base64 Encoding?

Base64 encoding makes sense in these scenarios:

Small, Critical Images

For tiny images that are essential to your email (like a small logo or icon that must display), base64 can ensure they always show up. Keep these under 5-10KB.

Transactional Emails

If you're sending transactional emails (receipts, password resets, etc.) where tracking isn't needed and you want to ensure brand elements always display, base64 can work well.

Simple Email Signatures

For personal email signatures where you want a small logo or headshot to always appear, base64 encoding can be effective.

When Should You Avoid Base64 Encoding?

Avoid base64 encoding in these cases:

Marketing Campaigns

If you need to track opens, clicks, and engagement, stick with externally hosted images. The tracking capability is far more valuable than the minor convenience of base64.

Large Images

Never base64 encode large images (photos, banners, product images). The file size bloat will hurt deliverability and user experience.

Newsletters with Multiple Images

For content-rich newsletters with several images, base64 encoding will make your email massive and likely to be clipped by Gmail or flagged by spam filters.

When Targeting Outlook Users

If a significant portion of your audience uses Outlook desktop clients, base64 images may not render correctly.

Best Practices for Base64 Encoding in Emails

If you decide to use base64 encoding, follow these guidelines:

  1. Keep it small: Only encode images under 10KB
  2. Use sparingly: Limit to 1-2 small images per email maximum
  3. Compress first: Optimize and compress images before encoding
  4. Test thoroughly: Check rendering across all major email clients
  5. Monitor email size: Keep total email size under 100KB to avoid Gmail clipping
  6. Provide alt text: Always include descriptive alt attributes for accessibility
  7. Have a fallback: Consider including a plain text version of your email

How to Base64 Encode an Image

If you want to experiment with base64 encoding, here are a few methods:

Online Tools

Numerous free online tools will convert images to base64. Simply upload your image and copy the resulting code.

Command Line (Mac/Linux)

bash base64 -i image.png -o output.txt

JavaScript

javascript // In Node.js const fs = require('fs'); const imageBuffer = fs.readFileSync('image.png'); const base64Image = imageBuffer.toString('base64');

Python

python import base64 with open("image.png", "rb") as image_file: encoded = base64.b64encode(image_file.read())

Conclusion

Base64 encoding images in emails is a double-edged sword. While it can ensure certain images always display and eliminates the need for external hosting, it comes with significant drawbacks: larger email sizes, no tracking capability, and inconsistent support across email clients.

The verdict: For most email marketing campaigns, externally hosted images are the better choice. Reserve base64 encoding for small, critical images in transactional emails where tracking isn't needed.

As with most email marketing decisions, testing is key. If you're considering base64 encoding, run A/B tests to see how it impacts your deliverability, rendering, and overall campaign performance. Your specific audience and email client distribution will determine whether base64 encoding is right for you.

P.S. If you found this useful, you're going to love our Email Subject Line Tester

Get More Opens With Every Email Send

Are your email subjects marking you as spam?
Are you being filtered as a 'Promotion' instead of a 'Priority'?

Start the test

Find out instantly.

X

If you like this article, you'll like our Subject Line Tester