Base64 is a binary-to-text encoding scheme defined in RFC 4648 that represents binary data as a string of ASCII characters. It uses a 64-character alphabet (A-Z, a-z, 0-9, +, /) and padding with '='. Base64 is used in email attachments (MIME), data URIs in HTML/CSS, JSON Web Tokens (JWT), and HTTP Basic Authentication. The URL-safe variant replaces '+' with '-' and '/' with '_' to avoid encoding issues in URLs.
What is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts binary data into a string of 64 printable ASCII characters: A-Z, a-z, 0-9, +, and /, plus = for padding. It was originally designed to transmit binary data over protocols that only support text, like SMTP (email) or early HTTP.
The encoding works by taking groups of 3 bytes (24 bits) and splitting them into 4 groups of 6 bits. Each 6-bit group maps to one of the 64 characters. If the input length isn't a multiple of 3, padding (=) is added to the output.
When should you use Base64 encoding?
Base64 is the right tool when you need to embed binary data in a text-only context:
- Data URIs — embed small images directly in HTML or CSS
- Email attachments — MIME encoding uses Base64 to attach files to emails
- JWT tokens — the header and payload of a JSON Web Token are Base64url-encoded
- HTTP Basic Auth — credentials are sent as a Base64-encoded
username:passwordstring - API payloads — binary data (files, images) sent inside JSON bodies
Base64 is not encryption. It's trivially reversible. Never use it to hide secrets or sensitive data.
What is the difference between URL-safe and standard Base64?
Standard Base64 uses + and / as two of its 64 characters, and = for padding. These characters have special meaning in URLs and filenames, which can cause issues when embedding Base64 in query strings, URL fragments, or file paths.
URL-safe Base64 (defined in RFC 4648 §5) solves this by replacing + with -, / with _, and omitting trailing = padding. This variant is used by JWT, many APIs, and anywhere Base64 appears in a URL context.
Working with API data formats? Our JSON ↔ YAML converter lets you switch between the two most common configuration formats instantly.