What is Base64 and when should you use it?
Try it now: Base64 Encoder/Decoder, free and private in your browser.
Open Base64 Encoder/DecoderBase64 is a way to write any data using only 64 safe text characters: letters, numbers, + and /. It lets binary data travel through systems built for plain text.
How it works
Base64 splits your data into groups of three bytes and turns each group into four characters. This is why the output is about 33% larger than the input.
Hello → SGVsbG8=
The = at the end is padding that fills out the last group.
Where developers use it
- Data URIs: embedding a small image directly in HTML or CSS.
- Email attachments: email was designed for text, so files are encoded.
- JWT tokens: the header and payload are Base64URL encoded.
- Basic authentication: credentials are encoded in the request header.
- APIs: sending small files inside JSON.
What Base64 is not
It is not encryption. Anyone can decode it instantly, so never use it to hide passwords or private data.
When to avoid it
Do not use Base64 for large images on a website. The extra size slows the page, and the browser cannot cache the image separately. Use a normal image file instead.
Base64 in code
// JavaScript (text only, no emoji)
btoa("Hello") // "SGVsbG8="
atob("SGVsbG8=") // "Hello"
# Python
import base64
base64.b64encode(b"Hello") # b'SGVsbG8='
The browser's btoa fails on characters outside Latin-1, such as emoji. Convert the text to UTF-8 bytes first, which is what our tool does.
A data URI example
A data URI puts a file straight into your HTML or CSS. It is handy for tiny icons, because it saves a network request:
<img src="data:image/png;base64,iVBORw0KGgo...">
Common mistakes
- Treating it as encryption. It hides nothing.
- Encoding twice. If decoded text still looks like Base64, it was encoded two times.
- Losing padding. Some systems strip the trailing
=. Add it back before decoding. - Line breaks. Email wraps Base64 at 76 characters. Remove the line breaks before decoding if your decoder complains.
Base64URL
A variant replaces + with - and / with _ so the result is safe inside URLs. JWTs use this form.
FAQ
- How much bigger is Base64 data?
- About 33% larger, because every 3 bytes become 4 characters.
- Is Base64 secure?
- No. It is an encoding, not encryption. Anyone can reverse it.
- Why does my Base64 end with = signs?
- They are padding that makes the output length a multiple of four.
- Can Base64 handle emoji?
- Yes, as long as the text is converted to UTF-8 bytes first. Our tool does this for you.