Base64 Encode/Decode
Encode text to Base64 or decode Base64 back to text. Supports UTF-8.
Privacy: All calculations run entirely in your browser. No data is sent to any server.
Plain Text
Encode →← Decode
Base64
What is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It is designed to safely transmit binary data over text-based protocols such as HTTP, SMTP, and JSON. The name "Base64" comes from the 64-character alphabet used in the encoding: uppercase letters A–Z, lowercase letters a–z, digits 0–9, and the symbols + and /. During encoding, every group of 3 input bytes (24 bits) is split into four 6-bit values, each mapped to one of those 64 characters. Because 3 bytes of input produce 4 characters of output, Base64-encoded data is approximately 33% larger than the original binary.
How Base64 Encoding Works
The Base64 encoding process takes input bytes and divides them into groups of 6 bits. Each 6-bit group is then mapped to a corresponding character from the Base64 alphabet. When the input length is not evenly divisible by 3 bytes, padding characters (=) are appended to the output: one = is added when there are 2 remaining bytes, and == is added when there is 1 remaining byte. This ensures the encoded output length is always a multiple of 4 characters.
// Encode
const encoded = btoa("Hello, World!");
// "SGVsbG8sIFdvcmxkIQ=="
// Decode
const decoded = atob("SGVsbG8sIFdvcmxkIQ==");
// "Hello, World!"
// Handle UTF-8 strings
const utf8Encode = btoa(unescape(encodeURIComponent("Héllo")));
const utf8Decode = decodeURIComponent(escape(atob(utf8Encode)));Common Use Cases
- Data URIs: Embedding images directly in CSS or HTML using
data:image/png;base64,...eliminates extra HTTP requests for small assets. - API Authentication: HTTP Basic Authentication encodes the
username:passwordpair in Base64 before sending it in the Authorization header. - Email Attachments: MIME encoding relies on Base64 to embed binary attachments such as images and documents inside plain-text email messages.
- JWT Tokens: The header and payload sections of JSON Web Tokens are Base64url-encoded, making them safe to include in URLs and HTTP headers.
- Storing Binary in JSON/XML: When binary data must be embedded in text-only formats like JSON or XML, Base64 encoding provides a reliable text representation.
Base64 vs Base64url
Standard Base64 uses the characters + and / as part of its 64-character alphabet. However, both of these characters have special meaning in URLs and file systems: + is interpreted as a space in query strings, and / is a path separator. Base64url is a URL-safe variant that replaces + with - (hyphen) and / with _ (underscore). It also typically omits the trailing = padding characters since they are percent-encoded in URLs. Base64url is the encoding used in JSON Web Tokens (JWTs), URL query parameters, and anywhere the encoded string must be safe for use in a URI or filename.
Frequently Asked Questions
- Is Base64 encryption?
- No. Base64 is an encoding scheme, not encryption. It provides no security — anyone can decode it. It is designed for data transport, not confidentiality. Never use Base64 to protect sensitive data.
- Why does Base64 output end with = or ==?
- The = characters are padding. Base64 processes input in groups of 3 bytes. If the input length isn’t a multiple of 3, padding characters are added: one = for 2 remaining bytes, == for 1 remaining byte.
- Does Base64 encoding increase file size?
- Yes. Base64 encoding increases data size by approximately 33%. Three bytes of input produce four characters of output. This overhead is the trade-off for text-safe encoding.
- Can I Base64 encode binary files like images?
- Yes. This tool handles text encoding. For files, the binary data is read and each byte is encoded. This is commonly used for data URIs in HTML/CSS to embed small images inline.
Guides
Related Tools
URL Encode/Decode
Percent-encode or decode URLs and query parameters.
JWT DecoderDecode and inspect JSON Web Tokens without sending them to a server.
Hash GeneratorGenerate MD5, SHA-1, SHA-256, and SHA-512 hashes from text.
HTML Entity Encoder/DecoderEncode special characters to HTML entities or decode them back.