Base64 Encoding Explained: What It Is, Uses and Common Myths
Base64 turns binary data into plain text so it can travel safely through systems built for text. Learn how it works, where it is used, and why it is not encryption.
Sooner or later, every developer, and plenty of marketers and site owners, comes across a long string of letters and numbers ending in one or two equals signs, something like SGVsbG8gUGF0bmEh. That is almost certainly Base64. It shows up in email attachments, API credentials, image data embedded in web pages and configuration files.
This guide explains what Base64 is, why it exists, where you will meet it and the one thing everyone should know: it is not a way to keep data secret. You can try every example below with our free Base64 encoder and decoder.
What is Base64 encoding?
Base64 is a way of representing any data, whether text, images, PDFs or anything else, using only 64 "safe" characters:
- Uppercase letters
A–Z(26) - Lowercase letters
a–z(26) - Digits
0–9(10) - Two symbols, usually
+and/
The equals sign = is used as padding at the end when needed. Because the output contains only these characters, it can pass through systems that were designed to handle plain text without being corrupted.
How it works, briefly
Computers store data as bytes, each made of 8 bits. Base64 takes the data 3 bytes (24 bits) at a time and splits those 24 bits into four groups of 6 bits. Each 6-bit group is a number from 0 to 63, which maps to one of the 64 characters. That is why Base64 output is roughly 33% larger than the original: every 3 bytes become 4 characters.
For example, the text Hello Patna! encodes to:
SGVsbG8gUGF0bmEh
Decoding that string gives back exactly Hello Patna!. Nothing is lost and nothing is hidden.
Why Base64 exists
Many older internet systems, email in particular, were built to carry plain text. Raw binary data, such as an image or a PDF, contains byte values that these systems might misinterpret, strip out or change, for instance by treating certain bytes as line endings or control characters. Base64 solves this by converting binary data into harmless text that survives the journey, and then converting it back at the other end.
Today it remains the standard answer whenever binary data has to be placed inside something text-based: an email, a JSON payload, an XML document, an HTML file or a URL.
Common uses of Base64
| Where | What Base64 does there |
|---|---|
| Email attachments | Encodes files so they can travel inside the text-based email format (MIME) |
| Data URIs | Embeds small images or fonts directly in HTML or CSS |
| APIs and JSON | Sends files, such as an uploaded document or signature image, inside a JSON field |
| HTTP Basic Authentication | Encodes username:password in a request header |
| JSON Web Tokens (JWT) | Uses a URL-safe Base64 variant for the token's header and payload |
| Config and certificates | Stores keys and certificates in text form, such as PEM files |
Data URIs: embedding images with Base64
A data URI lets you put a file directly inside HTML or CSS instead of linking to a separate file. It looks like this:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." alt="Small icon">
The part after base64, is the image itself, encoded as text. This can be handy for tiny icons or for HTML emails and single-file documents that must work offline. However, it has trade-offs:
- The encoded image is about a third larger than the original file.
- It cannot be cached separately by the browser, so it is downloaded again with every page or stylesheet that contains it.
- Large data URIs make HTML and CSS files bulky and harder to maintain.
As a rule of thumb, data URIs suit very small assets. For normal photos and banners, link to a properly compressed image file instead; our image compressor can help with that.
Base64 is not encryption
This is the most important point in this article. Base64 is an encoding, not encryption. There is no key and no secret. Anyone who sees a Base64 string can decode it instantly with any tool or one line of code.
That has practical consequences:
- Do not "hide" passwords, API keys or customer data by Base64-encoding them in your code, app or website. It offers no protection.
- HTTP Basic Authentication must run over HTTPS. The credentials are only Base64-encoded, so without HTTPS they can be read in transit.
- JWT payloads are readable. A JWT is signed to prevent tampering, but its contents can be decoded by anyone, so do not put sensitive information in it.
Encoding changes the format of data so systems can handle it. Encryption protects data so only authorised people can read it. Base64 only does the first.
If you need to protect data, use proper encryption and secure storage, such as hashed passwords with a modern algorithm, HTTPS for transport and encrypted secrets management.
How to encode and decode Base64 for free
Our free Base64 encoder and decoder encodes and decodes privately in your browser, so the text you paste is processed on your own device. To use it:
- Open the Base64 tool.
- Paste plain text to encode, or a Base64 string to decode.
- Choose encode or decode.
- Copy the result.
If you prefer code, most languages have Base64 built in. In PHP, base64_encode() and base64_decode(); in JavaScript in the browser, btoa() and atob() (for plain ASCII text); in Python, the base64 module.
Frequently asked questions
Why does Base64 often end with = or ==?
Base64 works on groups of 3 bytes. When the data is not an exact multiple of 3 bytes, one or two = characters are added as padding so the output length stays a multiple of 4.
What is URL-safe Base64?
Standard Base64 uses + and /, which have special meanings in URLs. The URL-safe variant replaces them with - and _, and often drops the padding. JWTs use this variant.
Does Base64 compress data?
No. It does the opposite, making data roughly a third larger. Its purpose is safe transport through text-based systems, not saving space.
Need help with secure web or app development?
Handling files, authentication and APIs correctly is a core part of building reliable software. Our web development and mobile app development teams build systems with sensible security practices from the start.
BaalBo Infotech is based in Patna and works with businesses across India. Get in touch if you would like to discuss your project.
Written by
Sukesh Kumar
Founder, CEO & Director, BaalBo Infotech
Sukesh founded BaalBo Infotech in Patna in 2023 and leads a team building websites, apps and online stores for businesses in India and abroad.
More about Sukesh