
The last chunk of input contains exactly 8 bits: Four zero bits are added to form two 6-bit groups. Then, one or two pad ( =) characters are output depending on the following cases. When the input has fewer than 24 bits at the end, zero bits are added (on the right) to form an integral number of 6-bit groups. Finally, each 6-bit group is converted to a single character in the Base64 alphabet by consulting the above Base64 alphabet table. These 24-bit groups are then treated as 4 concatenated 6-bit groups. It processes the input from left to right and organizes the input into 24-bit groups by concatenating three 8-bit bytes. The Base64 encoding algorithm receives an input stream of 8-bit bytes. Following is the mapping table which is also called the Base64 index or alphabet table. This mapping between the 6-bit binary sequence and the corresponding Base64 alphabet is used during the encoding process. The extra 65th character ( =) is used for padding.Įach of the 6-bit binary sequences from 0 to 63 are assigned a Base64 alphabet. The first 64 characters out of the 65-character subset are mapped to an equivalent 6-bit binary sequence ( 2 6 = 64). The Base64 encoding is described in the RFC 4648.īase64 encoding works with a 65-character subset of the US-ASCII charset.
#Base64 encoding python software#
The friend’s email software will Base64-decode the above encoded textual data to restore the original binary image. For example, when you send an email containing an image to your friend, your email software Base64 encodes the image and inserts the equivalent text into the message like so -Ĭontent-Disposition: inline filename =favicon-16x16.png Although, It was later extended to support non US-ASCII text messages as well as non-text messages such as audio and images, It is still recommended to encode the data to ASCII charset for backward compatibility.īase64 encoding encodes any binary data or non-ASCII text data to printable ASCII format so that it can be safely transmitted over any communication channel.

One example of such a system is Email (SMTP), which was traditionally designed to work with plain text data in the 7-bit US-ASCII character set.

It represents binary data in a printable ASCII string format by translating it into a radix-64 representation.īase64 encoding is commonly used when there is a need to transmit binary data over media that do not correctly handle binary data and is designed to deal with textual data belonging to the 7-bit US-ASCII charset only.

Base64 is a binary-to-text encoding scheme.
