Base64 Algorithm

Base64 is an algorithm for encoding byte data into ASCII string format (binary-to-text). The algorithm is the reverse, that is possible to convert the text back to a byte code without data loss. Base64 is very widely used in WEB technologies: to convert binary files into text for emails, for the conversion of graphic elements in HTML and CSS.

The Base64 algorithm is based on converting in groups of 3 bytes (3 * 8 bits = 24 bits) to a group of 6 bits (4 * 6 = 24 bits). Each 6-bit group is an index from 0 to 63, 64 in total, which is why the algorithm is called Base64. To convert to ASCII string format, the character set is used (according to RFC 4648 standard):

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

If there is not enough data to form a group of 3 bits, then the missing bits are filled with the symbol "="

Table of Base64 (RFC 4648)

IndexBinaryChar IndexBinaryChar IndexBinaryChar IndexBinaryChar
0000000A16010000Q32100000g48110000w
1000001B17010001R33100001h49110001x
2000010C18010010S34100010i50110010y
3000011D19010011T35100011j51110011z
4000100E20010100U36100100k521101000
5000101F21010101V37100101l531101011
6000110G22010110W38100110m541101102
7000111H23010111X39100111n551101113
8001000I24011000Y40101000o561110004
9001001J25011001Z41101001p571110015
10001010K26011010a42101010q581110106
11001011L27011011b43101011r591110117
12001100M28011100c44101100s601111008
13001101N29011101d45101101t611111019
14001110O30011110e46101110u62111110+
15001111P31011111f47101111v63111111/
Padding=

Example with word "HELLO"

HELLO 
7269767679
010010000100010101001100010011000100111100------
184211219460Padding
SEVMTE8=

HELLO -> SEVMTE8=