2.1 Composition of 64 Characters
Base64 gets its name from using 64 characters for encoding. These 64 characters were chosen because they are "safe" ASCII characters that are not easily misinterpreted or modified across various systems and protocols.
| Index Range | Characters | Count | Usage |
|---|---|---|---|
| 0 - 25 | A - Z | 26 | Uppercase |
| 26 - 51 | a - z | 26 | Lowercase |
| 52 - 61 | 0 - 9 | 10 | Numbers |
| 62 | + | 1 | Plus |
| 63 | / | 1 | Slash |
| (Padding) | = | - | Special padding char, not in index |
2.2 Base64 Index Table
This is the complete Base64 index table. In encoding and decoding, we map between Values (Index) and Characters using this table.
Examples:
Index 0 is A,
Index 26 is a,
Index 63 is /.
2.3 Padding Character =
Base64 encodes data in groups of 3 bytes (24 bits). If the input length is not a multiple of 3,
the = character is used as padding.
Padding Rules:
- ➊ Remainder 0 (Divisible) → No Padding
Ex: "ABC" (3 bytes) → "QUJD" - ➋ Remainder 1 (1 byte left) → Add two '='
Ex: "A" (1 byte) → "QQ==" - ➌ Remainder 2 (2 bytes left) → Add one '='
Ex: "AB" (2 bytes) → "QUI="
Padding not only aligns data but also tells the decoder the exact length of original data.