Guide
What Is Base64 and Why Is It Bigger?
Why Base64 output is about 33% larger, what the = padding means, and when JWTs and URLs need Base64URL instead of standard Base64.
Quick Answer
Base64 is a binary-to-text encoding format. It converts data into text characters so that binary information can be safely transmitted through systems designed primarily for text.
If you just need to encode or decode something right now, you can use the tool directly.
Try the Base64 Encoder and Decoder →What Is Base64?
Imagine you have a photograph saved on your computer. That photo is made up of raw binary data: millions of 0s and 1s. Now imagine you need to send that photo inside a text message or an email that only understands plain text characters. You have a problem.
Base64 solves this. It takes any kind of binary data and converts it into a safe string of
64 characters: the 26 uppercase letters (A–Z), the 26 lowercase letters (a–z), the digits
0–9, and the characters + and /. The result looks like random text,
but it is actually your original data in a different form.
The name "Base64" simply means the encoding uses a 64-character alphabet, the same way "base 10" means you count with 10 digits (0–9), and "base 2" means you count with 2 digits (0 and 1).
Why Was It Created?
In the early days of the internet, email systems were built strictly for plain text. The standard that defined email (called SMTP) was designed to carry 7-bit ASCII characters only. That covers the English alphabet, numbers, and basic punctuation.
The problem: photos, documents, spreadsheets, and other binary files contain byte values outside that range. When these files passed through old email servers, the servers would sometimes corrupt the data by stripping or mangling bytes they did not recognize.
Base64 was introduced as part of the MIME standard (Multipurpose Internet Mail Extensions) in the early 1990s to solve this problem. By converting binary data into pure ASCII text before sending it, the data could pass through any text-only system without corruption.
Today, Base64 is used far beyond email: it appears in APIs, web tokens, HTML data URIs, and many other contexts where binary data needs to travel through text-based channels. When you encode a UTF-8 string containing non-ASCII characters (Japanese text, Arabic, emoji) Base64 converts the byte sequence into a safe ASCII representation that any system can transmit without corruption.
How It Works
Base64 processes data in chunks of 3 bytes at a time. Each chunk of 3 bytes (24 bits) is split into 4 groups of 6 bits each. Each 6-bit group becomes one character from the Base64 alphabet. This is why the output is always longer than the input: 3 bytes become 4 characters.
Here is a simple example:
Hello SGVsbG8= Hello
The trailing = is padding. If the input length is not a multiple of 3 bytes,
padding characters fill out the final group so the decoder knows exactly where the data ends.
You may see one = or two ==, depending on how many bytes are left over.
Decoding is the exact reverse: each group of 4 Base64 characters is converted back to 3 bytes of original data. The result is byte-for-byte identical to the original input.
How Does "Man" Become TWFu?
Take the three letters "Man". In ASCII they are the bytes 77, 97 and 110, or
01001101 01100001 01101110 in binary. Base64 reads those 24 bits as four groups of
six: 010011 010110 000101 101110.
Those groups are the numbers 19, 22, 5 and 46. In the Base64 alphabet, 19 is T, 22 is W, 5 is
F and 46 is u, so "Man" becomes TWFu. Two letters, "Ma", leave the last group
short, so the output is TWE= with one padding sign. One letter, "M", gives
TQ== with two.
Why Is Base64 About 33% Bigger?
Every 3 bytes of input become 4 characters of output, so Base64 is 4/3 the size of the
original, about 33% larger. A 30 KB image becomes roughly 40 KB of text once you embed it as a
data URI, before the data:image/png;base64, prefix is even counted. Email adds a
little more, because MIME wraps Base64 into lines of 76 characters.
That cost is why data URIs suit small icons and not photos. This tool shows the expansion ratio next to the output. Short inputs read higher because of padding, and the figure settles near 1.33× as the input grows.
What Is the Difference Between Base64 and Base64URL?
Base64URL is the same encoding with two characters swapped, so the output is safe inside a URL or a filename:
- Characters 62 and 63: standard Base64 uses
+and/; Base64URL uses-and_. The bytes FB FF encode as+/8=in one and-_8=in the other. - Padding: standard Base64 keeps the
=signs; Base64URL usually drops them, because=also has a meaning in query strings. - Where you see it: standard Base64 in email attachments, data URIs and HTTP Basic auth; Base64URL in JWTs, OAuth tokens and signed URLs.
This tool encodes standard Base64. When you paste a Base64URL string to decode, it notices the
- or _ and offers to decode it as Base64URL instead of failing.
Real-World Uses
Base64 appears constantly in modern software:
- JWT tokens, JSON Web Tokens use Base64URL encoding (a URL-safe variant) to carry the header and payload sections. You can paste a JWT into a decoder to inspect its contents.
- Email attachments: Email clients encode attachments as Base64 before sending them through SMTP servers, then decode them on the receiving end.
- Images in HTML and CSS: Developers embed small images directly in web pages
as Base64 data URIs (
data:image/png;base64,...) to eliminate extra HTTP requests. - API responses and JSON payloads: When an API needs to return binary data (like a generated image or a PDF) inside a JSON response, it encodes the binary as a Base64 string.
- Authentication credentials: HTTP Basic Authentication sends usernames and passwords encoded as Base64 in the Authorization header.
Common Mistakes
These misunderstandings come up frequently:
History
Base64 was formally defined in RFC 1341 in 1992 as part of the MIME specification, which extended internet email to support attachments, multiple content types, and character sets beyond ASCII. Before MIME, email was strictly plain text and file sharing required separate protocols like FTP.
The specific 64-character alphabet was chosen because these characters are universally supported across all ASCII-compatible systems and do not carry special meaning in most text-based protocols. The encoding has remained essentially unchanged for over 30 years and is now defined in RFC 4648 (2006), which also specifies the Base64URL and Base32 variants.
Related Tools
You May Also Need
You may also need
- JSON FormatterFormat JSON payloads after decoding
- JWT DecoderDecode a whole JWT, header and payload, instead of one Base64url part
- Encoding DetectorName the encoding first when you are not sure the text is Base64
- URL Encoder and DecoderMake Base64 safe for URLs
Alternatives
- HTML Entity Encoder and DecoderEncode for HTML output instead