How do attachments get encoded in an email?
Still have a question, spotted an error, or have a better explanation or a source we should cite?
When you attach a file to an email, it can't travel as-is. SMTP (the protocol that delivers email) was built in the 1980s to handle plain text only, not binary files like PDFs, images, or spreadsheets. So your attachment gets converted into text before it travels, then converted back into a file when the recipient opens it.
This conversion process is called Base64 encoding. It takes the binary data of your file (the raw 1s and 0s) and translates it into a sequence of 64 printable ASCII characters (letters, numbers, and a few symbols). Every three bytes of binary data becomes four characters of text. That's why an attachment makes your email about 33% larger in transit, even though the recipient sees the original file size.
The encoding happens automatically when you attach a file. Your email client or ESP wraps the Base64-encoded data inside a MIME structure (Multipurpose Internet Mail Extensions), which is just a set of headers that tell the recipient's email client what type of file it is, what it's named, and how to decode it back into a usable file.
A typical MIME section for an attachment looks like this:
Content-Type: application/pdf; name="invoice.pdf" Content-Disposition: attachment; filename="invoice.pdf" Content-Transfer-Encoding: base64 JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL01l ZGlhQm94IFswIDAgNjEyIDc5Ml0KL0NvbnRlbnRzIDIgMCBSCj4+CmVuZG9iago...
The recipient's email client reads those headers, knows it's dealing with a PDF, decodes the Base64 text back into binary, and saves it as a file you can open. This all happens invisibly. You attach a file, they download a file. The encoding is just the disguise it wears in transit.
One practical consequence: if you're sending emails with large attachments (say, over 5MB), you're not just sending 5MB. You're sending 6.65MB after encoding, which is why some mail servers reject oversized attachments even when the original file seems under their limit. Many ESPs cap attachment sizes at 10MB or 25MB for this reason. If you're sending large files regularly, linking to a download instead of attaching directly keeps your emails lighter and faster to deliver.
Contributors
Who worked on this answer
Every name links to their profile. Every company links to their site. Real people, real accountability.