Base64 Encoder
Encode text or files to Base64, with URL-safe output and data URI generation.
Base64 Encoder tool
You can also drop a file onto this box to encode its bytes.
Paste the result into a CSS url() or an <img src> to embed
the file with no extra request. Encoding a file above fills the MIME type in for you.
Need the other direction? Use the Base64 Decoder.
What this tool does
Base64 rewrites arbitrary bytes using only 64 characters that survive systems built for text. This encoder takes what you type — or a file you drop on it — and produces that representation, with control over the alphabet, the padding and the line width.
Non-ASCII input is handled properly. The text is encoded as UTF-8 first, so an em dash or an
emoji becomes the right sequence of bytes rather than throwing the way the browser's own
btoa() does on anything above U+00FF.
Common uses
- Embedding a small image or font directly in CSS or HTML as a data URI, removing one network round trip on a critical asset.
-
Building an HTTP Basic credential: the header value is
Basicfollowed by the Base64 ofusername:password. - Putting binary into a JSON field, a YAML value or an environment variable, none of which can hold raw bytes.
- Encoding a certificate or key body for a Kubernetes secret, which expects Base64 values.
- Attaching a file to a MIME email body, where the 76-character line rule applies.
A short example
Three ASCII characters become four Base64 characters, exactly:
foo → Zm9v
fo → Zm8=
f → Zg== And a character outside ASCII becomes its UTF-8 bytes first:
é → C3 A9 → w6k= Choosing the alphabet and the padding
The standard alphabet ends with + and /. Both have meaning inside a
URL — + is a space in a form-encoded query, and / is a path
separator — so RFC 4648 §5 defines a URL-safe variant that uses - and
_ instead. Pick it whenever the value will appear in a path, a query parameter or
a filename.
The trailing = characters pad the output to a multiple of four. They carry no
data, and JSON Web Tokens omit them entirely. Turn padding off when the consumer expects it
off; leave it on when you are not sure, since almost every decoder accepts padded input.
Line wrapping exists for the same historical reason: RFC 2045 limits an encoded MIME body to 76 characters per line. It is cosmetic — decoders ignore the newlines — but some older mail and PEM parsers insist on it.
Worth knowing
Base64 is an encoding, not encryption. Anyone can reverse it in one step, so it hides nothing. It also costs space: every three bytes become four characters, so the output is about 33% larger than the input, before line breaks. For a 2 MB image that is 700 KB of extra payload that cannot be cached separately from the document it sits in — which is why data URIs are worth it for icons and rarely worth it for photographs.
Frequently asked questions
Why does my terminal produce a different string from this page?
Two reasons, and only one of them is harmless. echo secret | base64 encodes the newline that echo appends, so seven bytes go in rather than six — use printf %s or echo -n. Line wrapping also differs: GNU coreutils breaks at 76 characters unless you pass -w 0, while openssl base64 breaks at 64. Wrapping changes nothing after decoding; the extra byte does.
Why does Basic authentication fail with a colon or an accent in the password?
RFC 7617 §2 splits the credential at the first colon, so a colon inside the user-id is simply unrepresentable — one in the password is fine. Accents are murkier: the specification offers a charset="UTF-8" parameter, but servers written before it decode the bytes as ISO-8859-1, so a UTF-8 ä arrives as two wrong characters. Test with an ASCII password to tell the two failures apart.
Is Base64 the best way to inline an SVG in CSS?
Rarely. SVG is text, so percent-encoding it typically costs around a tenth of its size against Base64’s fixed third, and the markup stays readable in the stylesheet. Encode it with the URL encoder, remembering that # must become %23 or every fill="#fff" truncates the image at the colour. Reach for Base64 when the asset is already binary, such as a PNG or a WOFF font.