Base64 is a binary-to-text encoding scheme that converts binary data into a string of ASCII characters. It represents every three bytes of input (24 bits) as four ASCII characters drawn from a 64-character alphabet. This makes it safe for transmission through channels that only support text — email, URLs, JSON payloads, and HTML attributes.
Unlike encryption, Base64 provides zero security. Anyone can decode a Base64 string trivially. Its purpose is transport safety, not confidentiality.
The Base64 alphabet consists of:
A–Z (values 0–25)a–z (values 26–51)0–9 (values 52–61)+ (value 62) and / (value 63)There are also URL-safe variants that replace + with - and / with _.
Let's walk through encoding the string "Cat":
Q2F0Base64 operates on 3-byte chunks. When input isn't a multiple of 3, padding is needed:
===Some implementations accept unpadded Base64, but strict decoders expect the = padding characters.
| Variant | Alphabet Change | Use Case |
|---|---|---|
| Standard | +/ | Email (MIME), PEM certificates |
| URL-safe | -_ | JWT tokens, URL parameters |
| No padding | Omit = | URLs where padding causes issues |
| Base64url (RFC 4648) | -_, no padding | JWT, Web Crypto API |
Base64 increases data size by approximately 33% — every 3 bytes become 4 characters. For a 1 MB file, the encoded result is roughly 1.37 MB. This overhead matters when encoding large files or images.
At the CPU level, Base64 encoding is fast. Modern processors can encode hundreds of megabytes per second using vectorized instructions. In JavaScript, the built-in btoa() and atob() functions are highly optimized in V8 and SpiderMonkey.
btoa() only handles Latin-1. For UTF-8, you must first encode to bytes using TextEncoder, then Base64-encode the result.Q2F0 and q2f0 decode differently.+ and / characters can conflict with XML syntax. Use the URL-safe variant when embedding Base64 in XML attributes.Use Base64 when you need to embed binary data in text-based formats: inline images in HTML/CSS, binary payloads in JSON, authentication tokens, and email attachments. Avoid it for large assets — serving a 2 MB Base64-encoded image inline is worse than a 1.5 MB PNG file loaded via a separate HTTP request with proper caching headers.
RiseTop offers a free Base64 encoder/decoder that handles standard and URL-safe variants, UTF-8 text, and file uploads — try it for your next project.