O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

base64

The base64 module is used to encode and decode data using base 64, base 32, or base 16 encoding. Base 64 is commonly used to embed binary data in mail attachments.

Base 64 encoding works by grouping the data to be encoded into groups of 24 bits (3 bytes). Each 24-bit group is then subdivided into four 6-bit components. Each 6-bit value is then represented by a printable ASCII character from the following alphabet:

ValueEncoding
0–25ABCDEFGHIJKLMNOPQRSTUVWXYZ
26–51abcdefghijklmnopqrstuvwxyz
52–610123456789
62+
63/
pad=

If the number of bytes in the input stream is not a multiple of 3 (24 bits), the data is padded to form a complete 24-bit group. The extra padding is then indicated by special ‘=’ characters that appear at the end of the encoding. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required