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.