Base64 is a binary-to-text encoding scheme that converts binary data (images, files, bytes) into a string using only 64 printable ASCII characters. It is widely used when binary data must be embedded in text-based formats such as JSON, XML, email (MIME), HTML data URIs, or HTTP requests.
Characters: A–Z a–z 0–9 + /
Padding: = (added so length is multiple of 4)
A modified version designed to be safe in URLs, URIs, filenames, and query strings:
This avoids characters that have special meaning in URLs or need escaping.
| Property | Standard Base64 | URL-safe Base64 |
|---|---|---|
| Alphabet | A–Z a–z 0–9 + / | A–Z a–z 0–9 - _ |
| Padding | = (usually present) | Omitted in most implementations |
| Safe in URL path/query? | No (requires %2B %2F %3D escaping) | Yes (no escaping needed) |
| Common usage | Email (MIME), data URIs, basic auth | JWT, OAuth tokens, API keys, URL parameters |
| Input bytes (text) | Standard Base64 | URL-safe Base64 (no padding) |
|---|---|---|
| Hello | SGVsbG8= | SGVsbG8 |
| Man | TWFu | TWFu |
| Ma | TWE= | TWE |
| M | TQ== | TQ |
| 😊 (UTF-8) | 8J+Yig== | 8J-Yig |