Dev Explained
Base64 Explained: A Beginner's Guide to Encoding and Decoding
If you've ever seen a long jumbled string of letters, numbers, and a few plus signs and slashes, and wondered what it was, there's a good chance you were looking at Base64.
What Base64 actually is
Base 64 is a way of representing any kind of data, text, images, even entire files, using only 64 safe, printable characters: the letters A through Z, a through z, the digits 0 through 9, and typically + and /, with = used for padding at the end. It isn't encryption and it isn't compression. It's simply a translation, a different way of writing the exact same underlying data so that it can travel safely through systems that don't handle raw binary data well.
A helpful way to think about it: the word "Hello" encoded in Base64 becomes SGVsbG8=. Nothing is hidden or protected, it's just represented differently. Anyone can decode it back instantly, which is exactly why Base64 should never be mistaken for a security measure.
Why Base64 exists in the first place
Many older systems, especially email protocols, were originally built to handle plain text only, not raw binary data like images or attachments. Base64 solves this by converting that binary data into plain text characters that any text-based system can pass along safely, without corrupting the data or misinterpreting special characters along the way. That's the entire reason Base64 became standard for things like email attachments decades ago, and it's stuck around because the same underlying problem, safely moving binary data through text-only channels, still comes up constantly in modern web development.
Where you'll actually run into Base64
- Embedding small images directly inside CSS or HTML, instead of linking to a separate file.
- Sending binary data like files or images inside a JSON payload, since JSON only supports text.
- Storing authentication tokens and credentials in a format that's safe to pass around in URLs and headers.
- Email attachments, which is where Base64 became widely used in the first place.
- Data URLs, the long strings starting with
data:image/png;base64,you'll sometimes see in a page's source code.
Encoding versus decoding, in plain terms
Encoding means taking normal data and converting it into Base64 format. Decoding means taking that Base64 text and converting it back into its original form. The two are exact opposites of the same process, and a proper base64 encode decode tool simply lets you do both directions instantly, so you can convert text to base64 or take an existing Base64 string and turn it back into readable text or the original file.
Base64 in Python
Python includes Base64 support directly in its standard library:
import base64
text = "Hello"
encoded = base64.b64encode(text.encode("utf-8"))
print(encoded.decode("utf-8")) # SGVsbG8=
decoded = base64.b64decode(encoded).decode("utf-8")
print(decoded) # HelloNotice the text has to be converted to bytes before encoding, and the result is converted back to a readable string afterward. This two-step conversion is a normal part of working with base64 encode python, since Base64 technically operates on raw bytes, not text directly.
Base64 decode in JavaScript
JavaScript has built-in functions for basic Base64 work, though they're a little older and text with special characters needs a small extra step:
const text = "Hello"; const encoded = btoa(text); console.log(encoded); // SGVsbG8= const decoded = atob(encoded); console.log(decoded); // Hello
btoa encodes a string to Base64, and atob does the reverse, which is the core of base64 decode javascript in the browser. For text containing characters outside the basic ASCII range, encoding the string as UTF-8 bytes first avoids errors, the same underlying idea as the extra step in the Python example above.
What "base64 to string" and "text to base64" actually mean
These phrases describe the same encode and decode process from slightly different angles. Text to Base64 means you're starting with plain readable text and converting it into the encoded format. Base64 to string means the reverse, starting with an encoded Base64 string and converting it back into plain, readable text. A base64 translator or base64 converter online is simply a tool that handles both directions for you, without needing to write any code yourself.
A quick word on Base64 and file size
One tradeoff worth knowing: Base64 encoding makes data roughly 33 percent larger than its original binary form. This happens because Base64 represents every 3 bytes of original data using 4 characters. That's a reasonable cost for the compatibility it buys you, but it's part of why Base64 is generally used for small pieces of data, like icons or short tokens, rather than large files, where that size increase adds up quickly.
Try it yourself
The fastest way to actually understand Base64 is to encode and decode something yourself and watch what changes. You can do that directly with the free Base64 encoder and decoder on this site. Type or paste text to encode it instantly, or paste an existing Base64 string to decode it back to readable text, all processed locally in your browser with nothing sent to a server.
Common mistakes and misunderstandings
- Thinking Base64 is encryption. It provides no security at all, since anyone can decode it instantly.
- Forgetting the padding character
=when manually copying a Base64 string, which will break decoding. - Trying to decode text that isn't actually valid Base64, which produces garbled or broken output instead of a clear error in some tools.
- Using Base64 for large files without accounting for the roughly 33 percent size increase it adds.
The bottom line
Base64 is a simple, well-understood way of representing binary data as safe, plain text, nothing more mysterious than that. It shows up constantly across email, web development, and app configuration because the underlying problem it solves, safely passing data through text-only systems, hasn't gone away. Once you've encoded and decoded a string or two yourself, that block of letters and numbers stops looking cryptic and starts looking like exactly what it is.
Frequently asked questions
What is Base64?
Base64 is a way of writing binary data as plain text using 64 safe characters, so it can travel through systems that only handle text, such as email or JSON.
Is Base64 encryption?
No. Base64 is encoding, not encryption. Anyone can decode it instantly, so it must never be used to protect secrets.
Why does Base64 make data bigger?
Base64 represents every 3 bytes of data as 4 text characters, so the result is roughly one third larger than the original.
How do I decode Base64 in Python or JavaScript?
Python has a built-in base64 module, and JavaScript has built-in functions such as atob. You can also decode text instantly with the free Base64 tool on this site.