What is Base64?
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. It uses 64 printable characters (A-Z, a-z, 0-9, +, /) to encode binary data.
Quick Facts
| Full Name | Base64 Encoding |
|---|---|
| Created | 1987 (Privacy Enhanced Mail specification) |
| Specification | Official Specification |
How Base64 Works
Base64 encoding works by taking three bytes (24 bits) of binary data and converting them into four ASCII characters. Each character represents 6 bits of the original data. If the input length is not divisible by 3, padding characters (=) are added to make the output length a multiple of 4. This encoding increases the data size by approximately 33% but ensures the data can be safely transmitted through systems that only support ASCII text.
Key Characteristics
- Uses 64 printable ASCII characters for encoding
- Output is approximately 33% larger than input
- Padding with '=' characters when input length is not divisible by 3
- URL-safe variant uses '-' and '_' instead of '+' and '/'
- Reversible encoding - can be decoded back to original binary
- Not encryption - provides no security, only encoding
Common Use Cases
- Embedding images in HTML/CSS using data URIs
- Encoding email attachments (MIME)
- Storing binary data in JSON or XML
- Encoding authentication credentials in HTTP Basic Auth
- Transmitting binary data through text-only protocols
Example
Original: Hello World
Base64: SGVsbG8gV29ybGQ=
Original: {"key": "value"}
Base64: eyJrZXkiOiAidmFsdWUifQ==