What Is Base64 Encoding Used For?
Learn how Base64 turns bytes into text, why it appears in data URLs, email and JWTs, how much space it adds, and why it is not encryption.
By TIG Tools editorial teamPublished October 25, 20265 min read
Base64 is a way to represent binary data using a limited set of text characters. It is useful when a system expects text but needs to carry bytes, such as an email message or an inline image. It does not hide or protect the data: Base64 is encoding, not encryption.
How Base64 works
A file is made of bytes, and a byte can have any value from 0 to 255. Some systems handle text more easily than arbitrary byte values. Base64 represents each group of three bytes as four printable characters from a 64-character alphabet: uppercase letters, lowercase letters, digits, +, and /.
For example, the three ASCII characters Man are the bytes 4D 61 6E in hexadecimal. Base64 encodes those bytes as TWFu. The reverse operation converts TWFu back into the original three bytes.
If the input byte count is not divisible by three, Base64 uses = padding to complete the final group. The one-byte input M becomes TQ==. Padding is a formatting part of standard Base64; it does not represent extra source data. Some formats omit it when their rules allow that.
For text, the usual process is to first convert characters into bytes using a character encoding such as UTF-8, then Base64-encode those bytes. This matters for non-ASCII text: the same visible character can have a different byte representation under different character encodings. You can try text conversions with the Base64 Encoder / Decoder.
Common uses of Base64
Carrying binary data through text-based systems
Base64 is useful when a format or interface is designed around text but needs to include data that is not ordinary text. It converts bytes into printable characters, making the data easier to place in a text field, document, or message.
The conversion does not make the binary data smaller or turn it into meaningful text. It gives the bytes a text-compatible representation that can later be decoded back into the same bytes.
Data URLs and inline images
A data URL can contain a media type and data directly in a URL-like string. A Base64 form looks like this:
data:image/png;base64,iVBORw0KGgo...
Here, image/png identifies the media type, base64 indicates how the data is represented, and the final part contains the encoded image bytes. The ellipsis is only a placeholder; a real value contains the full encoded data.
Data URLs can be handy for small images or other resources that need to be included directly in a document or stylesheet. They can also make the containing HTML or CSS larger, and the data is not a separate file that can be requested and cached independently. For larger assets, a normal image URL is often more practical. The Image to Base64 tool can create an encoded representation of an image for this kind of use.
Email and MIME attachments
Email messages are structured using MIME, which allows a message to contain different content types, including attachments. Base64 is one of the transfer encodings MIME uses to represent binary content as text-safe characters. An email client can decode that representation to recover the attachment bytes.
This is a transport representation, not a change to the file itself. A Base64-encoded image attachment is still the same image after decoding. The encoded form is longer, and MIME wraps Base64 content into lines of at most 76 characters.
JWTs and Base64url
A compact JSON Web Token commonly has three dot-separated parts: a header, a payload, and a signature. In this format, the parts use Base64url, a URL-safe variation of Base64. It replaces + with - and / with _; padding is commonly omitted in JWT segments.
For instance, a token may look like:
eyJ... . eyJ... . abc...
The spaces above are for readability; an actual compact token has no spaces around the dots. Base64url makes the encoded segments suitable for use in URLs and related contexts. It does not make the header or payload secret. In a signed JWT, anyone who has the token can generally decode those parts and read their contents. The signature can help verify integrity and issuer, but it is not encryption. JWT also supports encrypted token forms, so whether a token is confidential depends on the token type and how it was created—not merely on Base64url. The JWT Decoder can help inspect a token's readable parts; it decodes in your browser and does not verify the signature. A valid token works like a password until it expires, so prefer expired or test tokens.
How much larger does Base64 make data?
Base64 represents every three input bytes with four output characters. For input length n bytes, the padded output length is 4 × ceil(n / 3) characters. When the input length is a multiple of three, the encoded form is about one-third longer than the original byte count. A final incomplete group may include padding characters.
For example, 300 bytes produce 400 Base64 characters. That is 100 more characters than the number of input bytes, before any surrounding syntax or line breaks. If you place encoded data in a data URL, the prefix adds more characters as well.
Base64 is not compression. It usually increases the amount of data, so it is not a good way to reduce file size. If the goal is to make an image smaller, use an appropriate image format or compression method rather than Base64 encoding.
Base64 is not encryption
Encoding changes how data is represented; it does not require a secret key. Anyone with a Base64 string can decode it using software or a tool. A Base64 string may look unfamiliar, but that is not a security barrier.
Do not use Base64 to protect passwords, API keys, private messages, or other confidential information. Use encryption designed for the purpose, and handle keys securely. If you only need to move data between systems, Base64 may be suitable—but it should not be treated as access control or privacy protection.
A practical example
Suppose you have a short text value, M, and need to send its bytes through a field that expects printable text. First, represent M as its UTF-8 byte. For this ASCII character, that byte is 4D in hexadecimal. Base64 represents the one-byte group as TQ==:
Original text: M
UTF-8 byte: 4D
Base64: TQ==
A receiver that Base64-decodes TQ== gets the byte 4D and can interpret it as M using the same character encoding. If the data were a PNG file instead, decoding would produce PNG bytes, not readable prose. The correct next step would be to save or process those bytes as an image.
When should you use it?
Use Base64 when a specific format or transport needs binary data represented as text, such as a MIME attachment, a small embedded resource, or a JWT segment. Keep in mind the extra size, the need to decode before using the original bytes, and the fact that the result is not secret. For ordinary links, use URL encoding when you need to escape URL characters; Base64 and URL encoding solve different problems.
Summary
- Base64 represents bytes with printable text characters, encoding each three bytes as four characters.
- It is used in places such as MIME email, data URLs, and JWT Base64url segments.
- The encoded data is about one-third larger for input lengths divisible by three; Base64 is not compression.
- Base64 is not encryption: anyone with the encoded value can decode it.
Try it now
Use the Base64 Encoder / Decoder for free, right in your browser. No sign-up, and your files stay on your device.
Open Base64 Encoder / Decoder