BASE64 TLDR
BASE64 is an encoding algorithm that converts binary data into text. This is essential for transmitting
binary files via protocols like SMTP (email) or HTTP, which may only support text-based data.
In addition to file transmission, BASE64 is commonly used to embed binary data directly into HTML, CSS,
and JavaScript files, which are inherently text-based.
The algorithm was standardized in
RFC 4648
in 2006 and uses a character set consisting of 64 specific
characters: [A-Z], [a-z], [0-9], '+', '/', and '='. While variants like Base32 and Base16 exist,
Base64 is the most widely used.
If you like to read more about the technical aspects of the BASE64 algorithm,
Wikipedia has an excellent page about it.
Samples
Try out these, if you would like to give it a go, and see how it works:
BASE64 encode 'Man'
BASE64 encode random lorem-ipsum!
BASE64 decode the encoded lorem ipsum
BASE64 decode 'TWFu'
BASE64 and email (SMTP, attachments and MIME types)
BASE64 encoding is essential for sending binary files, like images and documents, as email
attachments. Email protocols, such as SMTP, are designed to handle text data, and text data only, so binary
files must be encoded as text. This is where BASE64 comes in, encoding the binary data
into a text format that can be safely transmitted.
MIME (Multipurpose Internet Mail Extensions)
types further classify the data, ensuring that email clients correctly
interpret and display attachments.
Read more on MIME at Wikipedia.
BASE64 and web development
BASE64 is widely used in web development to embed binary data directly into HTML, CSS,
and JavaScript files. For instance, images, fonts, or other media can be encoded in
BASE64 and included as inline data. This allows multiple files to be loaded as part of a single
HTTP request
Bundeling data like this, may reducing server round-trips and improving performance. However,
it will also increase the size of web pages.
GeeksforGeeks has an excelent article about BASE64 encoded inline images.
BASE64 and data security
While BASE64 encoding is useful for converting binary data into text, it is not a security
measure. BASE64 does not encrypt data; it simply encodes it, making it easily reversible.