1. What is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format by translating it into a radix-64 representation. The standard index table consists of 64 characters:
• Uppercase letters: `A` to `Z` (indices 0–25)
• Lowercase letters: `a` to `z` (indices 26–51)
• Numerals: `0` to `9` (indices 52–61)
• Symbols: `+` (index 62) and `/` (index 63)
2. The 6-Bit Binary Conversion Math
Standard text and binary files use 8-bit bytes (1 byte = 8 bits). Base64 groups binary data into chunks of 6 bits (since 2⁶ = 64). Therefore, every 3 input bytes (24 bits) are converted into exactly 4 Base64 characters (4 × 6 = 24 bits).
Because 3 bytes turn into 4 characters, Base64 encoding introduces an exact ~33% overhead in payload size.
3. What Does the Equals Sign (=) Padding Mean?
If the input byte length is not divisible by 3, padding characters (`=`) are appended to the end of the output:
• 1 byte remainder: Converted into 2 Base64 characters + 2 padding signs (`==`).
• 2 byte remainder: Converted into 3 Base64 characters + 1 padding sign (`=`).
• 0 byte remainder: No padding required.
4. Common Web Development Use Cases
• Data URIs: Inlining small SVG or PNG images directly in HTML/CSS (`data:image/png;base64,...`) to save HTTP requests.
• Basic Authentication: Encoding `username:password` credentials in HTTP `Authorization: Basic <base64>` headers.
• JSON Web Tokens (JWT): Storing digitally signed claims in URL-Safe Base64 format across web applications.
Frequently Asked Questions
Is Base64 a form of encryption?
No. Base64 is an encoding format, NOT encryption. It provides zero cryptographic security and can be decoded instantly by anyone without a key.
What is URL-Safe Base64?
Standard Base64 contains `+` and `/`, which have special meanings in URLs. URL-Safe Base64 replaces `+` with `-` (minus) and `/` with `_` (underscore), and often omits `=` padding.