What Is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts binary data into a string of printable ASCII characters. It uses a set of 64 characters - A-Z, a-z, 0-9, +, and / - plus = for padding.
The primary purpose of Base64 is to safely transmit binary data through channels that only support text, such as email (MIME), HTML, JSON, and URLs.
How Base64 Works
The algorithm is straightforward:
- Take the input bytes
- Group them into blocks of 3 bytes (24 bits)
- Split each 24-bit block into 4 groups of 6 bits
- Map each 6-bit group to one of the 64 characters in the Base64 alphabet
- If the input isn't a multiple of 3 bytes, pad with
=
Step-by-Step Example
Encoding the string "Hi":
| Step | Data |
|---|---|
| ASCII bytes | H = 72, i = 105 |
| Binary | 01001000 01101001 |
| Pad to 24 bits | 01001000 01101001 00000000 |
| Split into 6-bit groups | 010010 000110 100100 000000 |
| Base64 index | 18, 6, 36, 0 |
| Base64 chars | S, G, k, A |
| Add padding | SGk= |
So "Hi" encodes to "SGk=".
Common Use Cases
Data URIs in HTML/CSS
Embed small images directly in HTML or CSS:
<img src="data:image/png;base64,iVBORw0KGgoAAAA..." />
API Authentication
HTTP Basic Authentication sends username:password as a Base64 string in the Authorization header:
Authorization: Basic dXNlcjpwYXNzd29yZA==
Email Attachments (MIME)
Email protocols like SMTP only handle 7-bit ASCII. Binary attachments (images, PDFs) are Base64-encoded before transmission.
JWT Tokens
JSON Web Tokens use Base64url encoding (a URL-safe variant) for the header and payload segments.
Base64 Is NOT Encryption
A critical misconception: Base64 is encoding, not encryption. It provides zero security - anyone can decode a Base64 string instantly. Never use Base64 to protect sensitive data. Use proper encryption (AES, RSA) instead.
Base64 Size Overhead
Base64 increases data size by approximately 33%. Every 3 input bytes become 4 output characters. For large files, this overhead matters - which is why Base64 data URIs are typically used only for small assets (icons, fonts under 10KB).
Base64url Variant
Standard Base64 uses + and /, which have special meaning in URLs. The Base64url variant replaces:
+→-/→_=padding → omitted
This variant is used in JWTs, URL parameters, and filenames.
Try It Yourself
Use our Base64 Encoder & Decoder to encode and decode text instantly - entirely in your browser with no server-side processing.

