Digital communications channels such as email (SMTP) and URL query strings were originally designed to transmit only 7-bit ASCII text. When engineers needed to send raw 8-bit binary data (such as images, file attachments, and cryptographic signatures), they developed Base64 encoding.
1. What is Base64?
Base64 is a standardized encoding scheme specified by RFC 4648. It maps arbitrary binary byte sequences into a safe set of 64 printable ASCII characters: uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and two special symbols (+ and /).
2. The 3-to-4 Byte Mathematical Mechanics
The algorithm groups input data in 24-bit blocks (3 bytes). These 24 bits are partitioned into 4 separate 6-bit numbers (since 2^6 = 64). Each 6-bit value acts as an index into the 64-character lookup table:
3 Input Bytes: [01001101] [01100001] [01101110] (24 bits = "Man")
4 Output Chunks: [010011] [010110] [000101] [101110]
Base64 Index: 19 22 5 46
Base64 Output: T W F u => "TWFu"3. Why Equals Sign (=) Padding is Needed
If the input byte length is not divisible by 3, the encoder appends zero bits to complete the final 6-bit group and appends one or two equals signs (=) as padding so the recipient parser knows the exact byte count.
4. URL-Safe Base64 Variants
Standard Base64 contains + and /, which have reserved syntactic meanings in URLs. In URL-safe Base64 (used in JWTs and OAuth), + is replaced with - and / is replaced with _, often omitting the trailing = padding.
5. The "Base64 Encryption" Myth
Base64 is not encryption. There is no secret key or mathematical barrier. Anyone in possession of a Base64 string can reverse it instantly. Never use Base64 to protect confidential credentials or user passwords.