Base64 Algorithm
Base64 is a highly effective algorithm for encoding byte data into ASCII string format, known as binary-to-text conversion. What makes this algorithm unique is its ability to decode the text back to its original byte code without any data loss. This makes it a widely popular choice in web technologies, especially for converting binary files into text for emails and converting graphic elements encoded in HTML and CSS. Its versatility and efficiency make it an essential tool for any web developer or tech enthusiast.
The Base64 algorithm is a method of encoding data that involves grouping bytes in sets of three (each containing 8 bits, for a total of 24 bits) and then converting each set into a group of four 6-bit values. These 6-bit values represent an index between 0 and 63 for 64 possible indexes, so the algorithm is called Base64. An ASCII character set is used to convert this encoded data into a human-readable format; by the RFC 4648 standard, this character set assigns specific characters to the 64 possible 6-bit values, allowing the encoded data to be translated into its original form.
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
If there is insufficient data to form a group of 3 bits, the missing bits are filled with the symbol "=."
Table of Base64 (RFC 4648)
Index | Binary | Char | Index | Binary | Char | Index | Binary | Char | Index | Binary | Char | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 000000 | A | 16 | 010000 | Q | 32 | 100000 | g | 48 | 110000 | w | |||
1 | 000001 | B | 17 | 010001 | R | 33 | 100001 | h | 49 | 110001 | x | |||
2 | 000010 | C | 18 | 010010 | S | 34 | 100010 | i | 50 | 110010 | y | |||
3 | 000011 | D | 19 | 010011 | T | 35 | 100011 | j | 51 | 110011 | z | |||
4 | 000100 | E | 20 | 010100 | U | 36 | 100100 | k | 52 | 110100 | 0 | |||
5 | 000101 | F | 21 | 010101 | V | 37 | 100101 | l | 53 | 110101 | 1 | |||
6 | 000110 | G | 22 | 010110 | W | 38 | 100110 | m | 54 | 110110 | 2 | |||
7 | 000111 | H | 23 | 010111 | X | 39 | 100111 | n | 55 | 110111 | 3 | |||
8 | 001000 | I | 24 | 011000 | Y | 40 | 101000 | o | 56 | 111000 | 4 | |||
9 | 001001 | J | 25 | 011001 | Z | 41 | 101001 | p | 57 | 111001 | 5 | |||
10 | 001010 | K | 26 | 011010 | a | 42 | 101010 | q | 58 | 111010 | 6 | |||
11 | 001011 | L | 27 | 011011 | b | 43 | 101011 | r | 59 | 111011 | 7 | |||
12 | 001100 | M | 28 | 011100 | c | 44 | 101100 | s | 60 | 111100 | 8 | |||
13 | 001101 | N | 29 | 011101 | d | 45 | 101101 | t | 61 | 111101 | 9 | |||
14 | 001110 | O | 30 | 011110 | e | 46 | 101110 | u | 62 | 111110 | + | |||
15 | 001111 | P | 31 | 011111 | f | 47 | 101111 | v | 63 | 111111 | / | |||
Padding | = |
Example with the word "HELLO"
H | E | L | L | O | |||||||||||||||||||||||||||||||||||||||||||
72 | 69 | 76 | 76 | 79 | |||||||||||||||||||||||||||||||||||||||||||
0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | - | - | - | - | - | - |
18 | 4 | 21 | 12 | 19 | 4 | 60 | Padding | ||||||||||||||||||||||||||||||||||||||||
S | E | V | M | T | E | 8 | = |
HELLO -> SEVMTE8=