Base64
The conceptWhy an email attachment grows by a third when you send it
Base64 writes any file as plain text using only 64 safe characters: A–Z, a–z, 0–9, + and /. Email was designed to carry text, so a photo you attach is converted to Base64 before it travels.
The price is size. Every 3 bytes of the file become 4 characters, so a 3 MB photo travels as about 4 MB of text, plus a little for line breaks.
What it’s forWorks out how many characters Base64 produces for a file of a given size.
L = 4 · ⌈n / 3⌉
- L
- length of the Base64 text, in characters
- n
- size of the original data, in bytes
- ⌈ ⌉
- round up to the next whole number
- 4, 3
- every group of 3 bytes becomes 4 characters
What it givesThe encoded length, which is about 33% bigger than the original for large files.
- n = 10 bytes: 10 ÷ 3 = 3.33, round up to 4
- L = 4 × 4 = 16 characters
- 16 characters for 10 bytes is 60% extra; big files approach 33%