What Is Base64?
Base64 is an encoding scheme that converts binary data into a string of ASCII characters from a 64-character alphabet (A-Z, a-z, 0-9, +, /). It was designed to allow binary data to be transmitted over systems that only support text, such as email servers and HTTP headers.
How Base64 Works
Base64 groups every three bytes of input (24 bits) into four groups of 6 bits each, then maps each 6-bit value to a character from its alphabet. This is why Base64 output is always a multiple of 4 characters and is approximately 33% larger than the input.
Common Use Cases
- Data URIs: Embedding images directly in HTML/CSS
- Email attachments: MIME encoding for binary attachments
- JWT tokens: Header and payload are Base64URL encoded
- HTTP Basic Auth: Credentials encoded as username:password
- API responses: Binary file content in JSON APIs
Base64 Is Not Encryption
Base64 encoding is reversible by anyone without a key. Never use it to protect sensitive data. It is purely an encoding scheme for compatibility, not a security mechanism.