Base64 encoding requires that 3 8-bit bytes (3*8=24) be converted into 4 6-bit bytes (4*6=24), and then 2 0s are added in front of 6-bit bytes to form 8-bit bytes. If the remaining characters are less than 3 bytes, fill in with 0, and the output characters use '=', so 1 or 2 '=' may appear at the end of the encoded output.
In order to ensure that the output encoding bit readable characters, Base64 developed an encoding table for unified conversion. The size of the encoding table is 2^6=64, which is also the origin of the name Base64.
Base64 Encode Table
| Code | Char | Code | Char | Code | Char | Code | Char | Code | Char | Code | Char | Code | Char | Code | Char |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | A | 8 | I | 16 | Q | 24 | Y | 32 | g | 40 | o | 48 | w | 56 | 4 |
| 1 | B | 9 | J | 17 | R | 25 | Z | 33 | h | 41 | p | 49 | x | 57 | 5 |
| 2 | C | 10 | K | 18 | S | 26 | a | 34 | i | 42 | q | 50 | y | 58 | 6 |
| 3 | D | 11 | L | 19 | T | 27 | b | 35 | j | 43 | r | 51 | z | 59 | 7 |
| 4 | E | 12 | M | 20 | U | 28 | c | 36 | k | 44 | s | 52 | 0 | 60 | 8 |
| 5 | F | 13 | N | 21 | V | 29 | d | 37 | l | 45 | t | 53 | 1 | 61 | 9 |
| 6 | G | 14 | O | 22 | W | 30 | e | 38 | m | 46 | u | 54 | 2 | 62 | + |
| 7 | H | 15 | P | 23 | X | 31 | f | 39 | n | 47 | v | 55 | 3 | 63 | / |