Base64 for Email Attachments: How MIME Encoding Works

Every image, PDF or zip file you've ever emailed traveled through the internet as plain text, thanks to Base64. Here's why that's necessary and how the format actually works.

Email was built for text, not binary

SMTP, the protocol email runs on, was designed in an era when messages were assumed to be 7-bit ASCII text. Many mail relays along the way were never guaranteed to pass arbitrary binary bytes through unchanged — some would strip the high bit, interpret certain byte sequences as control codes, or mangle line endings. Attaching a raw binary file directly risked silent corruption.

MIME's solution: Base64 + line wrapping

MIME (RFC 2045) solves this by Base64 encoding binary attachments into safe ASCII text, then wrapping the result at 76 characters per line with CRLF line breaks — a stricter variant of plain Base64. This is different from the unwrapped Base64 used in data URIs or JWTs, which don't need to survive line-length-limited legacy transports. Try it yourself with the MIME Base64 encoder.

What the raw email actually contains

If you view an email's raw source, an attachment appears as a MIME part with headers like Content-Type: image/png and Content-Transfer-Encoding: base64, followed by the Base64-encoded, line-wrapped body. Your mail client decodes this automatically and re-renders the original file — it's Base64 all the way down.

The size cost

Base64 adds roughly a 33% size overhead on top of line-break characters, so a 3 MB attachment becomes a bit over 4 MB of actual message payload — one reason many email providers cap attachment size well below their stated mailbox storage limits.

Note: this is not encryption

Like all Base64 use, MIME encoding provides zero confidentiality — see is Base64 encryption?. Anyone who intercepts the raw email can decode the attachment trivially; real confidentiality for email comes from transport encryption (TLS between mail servers) or end-to-end encryption standards like PGP/S-MIME.

Base64 for Email Attachments — FAQ

Why are email attachments Base64 encoded?+

Email (SMTP) was originally designed to carry only 7-bit ASCII text. Base64 turns any binary file — images, PDFs, zip archives — into plain ASCII text so it can travel safely through the email system.

What is MIME in relation to email attachments?+

MIME (Multipurpose Internet Mail Extensions, RFC 2045) is the standard that defines how email messages carry multiple parts (text, HTML, attachments), including the rule that binary parts are Base64 encoded and wrapped at 76 characters per line.

Why is the line wrapped at 76 characters?+

Historic SMTP relays enforced maximum line lengths and were not fully 8-bit clean; wrapping at 76 characters (with CRLF) keeps every line safely within limits that all mail servers were guaranteed to support.

Does this affect attachment file size?+

Yes — Base64 adds about 33% overhead on top of the line-break characters, so a 3 MB attachment becomes roughly 4 MB or slightly more of email payload data.