Why Use Base64?
Base64 is designed to carry data across channels that are built to support only text transmission, such as email (MIME), XML, JSON, or URL query parameters:
- Safe Transmission: Prevents network equipment or legacy software from modifying control characters or non-printable binary streams.
- Embed Assets: Often used to embed small binary files, such as images or icons, directly inside CSS files or HTML source markup.
How Base64 Works
The Base64 alphabet consists of 64 characters: uppercase letters `A-Z`, lowercase letters `a-z`, digits `0-9`, and symbols `+` and `/`.
- Every group of 3 bytes (24 bits) of input data is divided into 4 chunks of 6 bits each.
- Each 6-bit chunk maps to one of the 64 characters in the index sheet.
- If the input bytes are not divisible by 3, the final Base64 string is padded with one or two `=` characters. E.g. "A" (1 byte) becomes "QQ==".