Base64 Encoder and Decoder: what it is and how to use it
Learn how Base64 encoding and decoding works, when to use it, why it is not encryption, and how to convert text in your browser.
Base64 turns bytes into text. That sounds simple, but it solves a useful compatibility problem: some systems handle text reliably but do not handle arbitrary binary data well.
An image, file, or byte sequence can be encoded as Base64 and placed inside JSON, HTML, CSS, an email body, or another text-only format. The receiver decodes it to recover the original bytes.
Base64 is encoding, not encryption. Anyone who has the encoded value can decode it.
What Base64 looks like
The standard Base64 alphabet contains:
- Uppercase letters
A-Z - Lowercase letters
a-z - Digits
0-9 +and/=as optional padding at the end
For example:
Hello, world!
SGVsbG8sIHdvcmxkIQ==
The encoded text is longer than the input. Base64 converts three bytes into four characters, so the result is usually about 33% larger. That extra size is the trade-off for making binary data safe to carry through text-based systems.
How encoding works
Base64 takes the input bytes in groups of three. Those 24 bits are split into four groups of six bits. Each six-bit value maps to one character in the Base64 alphabet.
If the input does not contain a complete group of three bytes, the encoder adds = padding so the output length is a multiple of four. Padding does not add original data; it tells the decoder how many bytes belong to the final group.
The details matter when a value has line breaks, missing padding, or non-ASCII characters. See why Base64 line breaks and padding break strings for those edge cases.
How to encode and decode Base64
For a quick conversion, use the Base64 Encoder / Decoder:
- Paste text or Base64 into the input.
- Click Encode to produce Base64, or Decode to recover the original text.
- Swap directions when you need to move between the two operations.
- Copy or download the result.
Everything runs in your browser. The value you paste is not uploaded or stored.
For JavaScript, the browser provides btoa() and atob() for basic ASCII input:
const encoded = btoa('Hello, world!')
const decoded = atob(encoded)
Those functions are byte-oriented, so they need extra UTF-8 handling for characters such as é, emoji, or non-Latin scripts. A tool that explicitly handles UTF-8 avoids that common trap.
Python has built-in support too:
import base64
encoded = base64.b64encode('Hello, world!'.encode('utf-8')).decode('ascii')
decoded = base64.b64decode(encoded).decode('utf-8')
Common uses for Base64
Data URLs
Small images can be embedded directly in HTML or CSS as a data URL:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...
This can be convenient for tiny icons or self-contained demos. It is usually a poor choice for large images because Base64 increases size and prevents normal browser caching of the separate asset.
JSON and API payloads
APIs sometimes need to carry a file or arbitrary bytes inside a JSON document. Base64 gives the bytes a text representation that fits in a JSON string.
It is still worth asking whether multipart uploads or object storage would be better for large files. Base64 makes transport possible; it does not make the data smaller.
Email attachments
Email systems historically relied on text-safe encodings for binary attachments. MIME Base64 often includes line breaks at fixed intervals. Those line breaks may need to be removed before passing the value to a strict decoder.
Tokens and identifiers
JWTs use Base64URL for their header and payload. Base64URL replaces + and / with URL-safe characters and often omits padding. It is related to standard Base64 but is not identical. A normal Base64 decoder may reject a JWT segment.
The JWT decoder can inspect a token without requiring its signing secret. Decoding a JWT does not verify its signature, and Base64 itself provides no security.
What Base64 does not do
Base64 does not:
- Encrypt data
- Hide secrets
- Compress files
- Authenticate a message
- Prevent someone from editing the encoded value
Never use Base64 as a replacement for encryption. If a value is sensitive, use authenticated encryption and manage the key separately. If you need to verify that data was not changed, use a cryptographic signature or a suitable hash in the correct security design.
The short version
Use Base64 when binary data needs to travel through a text-only format. Encode bytes before transport and decode them at the destination. Expect the result to be larger, handle UTF-8 explicitly, and remember that encoding is not security.
For a one-off conversion, use the Base64 Encoder / Decoder. For line breaks, padding, and Unicode edge cases, read the Base64 pitfalls guide.