Base64 Encoding Explained: How to Encode and Decode Data Online
September 5, 2026 · 5 min read
Base64 encoding is everywhere in modern development, yet many developers use it without fully understanding how it works or when it is appropriate. From JWT tokens and API payloads to email attachments and inline images in CSS, Base64 is the standard way to represent binary data as text-safe characters.
What Is Base64?
Base64 is a binary-to-text encoding method that converts any type of data — files, images, or raw bytes — into a sequence of ASCII-friendly characters. It uses a 64-character alphabet (A-Z, a-z, 0-9, +, /) plus padding with the = character. The result is a text string that can safely travel through systems designed for text, like email protocols, JSON payloads, and URL parameters.
How It Works
Base64 takes three bytes of binary data (24 bits) and splits them into four groups of 6 bits each. Each 6-bit group maps to one of the 64 characters in the Base64 alphabet. This means the encoded output is always about 33 percent larger than the original data — three bytes become four characters.
When the input is not a multiple of three bytes, padding characters (=) are added to complete the final group. One padding character means two bytes were encoded; two padding characters mean one byte was encoded.
When to Use Base64
Email attachments — email protocols were designed for text. Binary files like PDFs, images, and documents are Base64-encoded before being embedded in email messages.
Data URIs — small images can be embedded directly in HTML or CSS as Base64 strings, eliminating the need for separate image file requests. This can improve page load time for small icons and logos.
API communication — when sending binary data through JSON APIs, Base64 encoding ensures the data survives the text-based transmission without corruption.
JWT tokens — JSON Web Tokens use Base64URL encoding (a URL-safe variant) for their header and payload sections.
When NOT to Use Base64
Base64 is not encryption. It provides zero security — anyone can decode a Base64 string instantly. Never use it to protect sensitive information. It is also not compression — it actually makes data 33 percent larger. For large files, use proper binary transfer methods instead of Base64 encoding.
Common Pitfalls
Padding errors — mixing standard Base64 (with = padding) and Base64URL (without padding) causes decoding failures. Know which variant your system expects.
Character set confusion — standard Base64 uses + and /, while Base64URL uses - and _. Using the wrong alphabet produces corrupt output.
Large file encoding — Base64-encoding a 10 MB image produces a 13.3 MB string. For large files, this overhead is significant and usually unnecessary.
Encode and Decode Now
Our free Base64 Encoder/Decoder handles both encoding and decoding in your browser. Paste a string, encode it, or paste a Base64 string and decode it — instantly and privately.
Open Base64 Encoder →Need to test patterns in your decoded data? Our Regex Tester lets you search and match text with regular expressions.