Base64 Encoding & Decoding Explained
Base64 is a ubiquitous group of binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.
It is practically used to avoid data corruption when transferring data via legacy protocols that are not 8-bit clean (like email). It ensures that data remains intact without modification during transport.
Common Use Cases
- HTTP Authentication: Basic Auth uses Base64 to encode `username:password` strings.
- Email Attachments: Binary files (images, PDFs) are encoded to Base64 to survive the email transfer process.
- Data URLs: Embedding small images or fonts directly into CSS or HTML files (`data:image/png;base64,...`) to reduce HTTP requests.
- JSON/XML embedding: Including binary data inside standard text-based formats.
How does it work?
Base64 works by breaking binary data into 6-bit chunks. Each 6-bit chunk has a value between 0 and 63, which maps to a specific character in the Base64 alphabet (`A-Z`, `a-z`, `0-9`, `+`, `/`).
Note: Base64 is NOT encryption. It is encoding. Anyone can decode it. Do not use it to hide sensitive secrets without proper encryption.