A developer's guide to Base64 encoding — how the algorithm works, its 33% size overhead, and when to use standard vs URL-safe Base64.
Calculate your numbers instantly in your browser. Fast, free, no signup.
If you've spent any time working with web APIs, authentication headers, or email attachments, you have undoubtedly encountered Base64 encoding. It looks like a random string of alphanumeric characters ending in an equals sign, like SGVsbG8gV29ybGQ=.
But what exactly is Base64, and why do developers use it everywhere?
Base64 is an encoding scheme used to represent binary data (like images, files, or compiled code) as an ASCII string format. It translates the data into a standard alphabet consisting of 64 printable characters: A-Z, a-z, 0-9, +, and /.
In the early days of the internet, text-based systems like email (SMTP) were designed to handle only standard ASCII text. If you tried to send binary data (like an image attachment), the systems would often misinterpret the non-printable binary characters, corrupting the file.
Base64 was created to solve this problem. By encoding binary data into safe, printable ASCII characters, systems could easily transmit complex files without any risk of corruption.
The Base64 algorithm takes 3 bytes of binary data (24 bits total) and splits them into 4 chunks of 6 bits each. Each 6-bit chunk maps to one of the 64 characters in the Base64 index.
Because it turns 3 bytes into 4 bytes, Base64 encoding introduces a 33% size overhead. A 3MB image will become a 4MB Base64 string. Because of this bloat, you should avoid Base64 encoding large files unless absolutely necessary.
Despite the size overhead, Base64 is heavily used in modern web development:
<img src="data:image/png;base64,...">) to reduce HTTP requests.Because the standard Base64 alphabet includes + and /, which have special meanings in URLs, a "URL-safe" variant exists. It replaces the + with a - (hyphen) and the / with an _ (underscore).
Need to encode or decode a string right now? Use our free, browser-based Base64 Encoder/Decoder. It supports standard and URL-safe formats instantly, with zero data sent to our servers.