What is Base64 Encoding?
Base64 encoding is a method to represent binary data as an ASCII string. It converts binary data into a 64-character alphabet (A–Z, a–z, 0–9, +, /) to make it safe for transmission over text-based systems like email or APIs. Each group of 6 bits in the input is mapped to one of these characters, increasing the data size by ~33%.
Important: Base64 is encoding, not encryption. It is easily reversible and provides no security — do not use it to protect sensitive data.
How Base64 encoding works
- Divide the input into 3-byte (24-bit) chunks
- Split each 24-bit chunk into four 6-bit groups
- Map each 6-bit value to a Base64 alphabet character (0–63)
- Add
=padding if the input length is not a multiple of 3
Example: "Man" → binary 010011 010110 000101 101110 → values 19, 22, 5, 46 → Base64: TWFu
Common use cases
| Use case | Example |
|---|---|
| JWT tokens | Header.Payload.Signature — all Base64URL encoded |
| Email attachments | MIME encoding of binary files |
| Data URLs | data:image/png;base64,... in HTML/CSS |
| HTTP Basic Auth | username:password encoded in Authorization header |
| API tokens | Binary keys encoded as text for JSON or HTTP headers |
Base64 vs Base64URL
Standard Base64 uses + and / which are not safe in URLs. Base64URL (RFC 4648 §5) replaces them with - and _, and omits the = padding. This variant is used in JWT tokens and OAuth flows.
