

The Base64 encoded data ends up being longer than the original data, so that as mentioned above, for every 3 bytes of binary data, there are at least 4 bytes of Base64 encoded data.

It uses A-Z, a-z, and 0-9 for the first 62 values, and + and / for the last two values. This character set is considered the most common character set, and is referred to as MIME's Base64. As shown in the first section, those characters are A-Z, a-z, 0-9, +, and / (count them, did you notice they add up to 64?). Base64 Encodingīase64 encoding is the process of converting binary data into a limited character set of 64 characters. Base64 is basically used for representing data in an ASCII string format.Īs mentioned in the introduction of this article, without Base64 sometimes data will not be readable at all. Why Do We Use Base64?īase64 is very important for binary data representation, such that it allows binary data to be represented in a way that looks and acts as plain text, which makes it more reliable to be stored in databases, sent in emails, or used in text-based format such as XML. The term Base64 is taken from the Multipurpose Internet Mail Extensions (MIME) standard, which is widely used for HTTP and XML, and was originally developed for encoding email attachments for transmission. For instance, using this encoding, three 8-bit bytes are converted into four 6-bit groups. This is done using only the characters A-Z, a-z, 0-9, +, and / in order to represent data, with = used to pad data. What Is Base64?īefore moving more deeper in the article, let's define what we mean by Base64.īase64 is a way in which 8-bit binary data is encoded into a format that can be represented in 6 bits. The program is illustrated as a standalone local program, but you can apply the concept to different applications like sending your encoded image from your mobile device to a server, and many other applications. In this article, I will show you how we can use Python to encode and decode a binary image. What would be the workaround to avoid such an issue? The answer is Base64 encoding.

Well, it seems that you attempted to send your file in its raw bits and bytes format, while the media used was designed for streaming text. You're amazed that the file wasn't received properly on the other side-the file just contained strange characters! Say you have a binary image file you wanted to transfer across a network.
