webtools

Base64 Encode

Private: nothing leaves your browser

Result
output

                  

Waiting for text

Turn text into Base64 as you type, in the standard alphabet or the URL safe one. Drop a file on the box to get a complete data: URI you can paste straight into CSS or HTML. Emoji and accented letters encode correctly.

About encoding to Base64

Encoding to Base64 is how bytes get carried through a channel that only accepts text. The usual reasons are an image inlined in a stylesheet as a data URI, a small file put inside a JSON field, credentials for an HTTP Basic auth header, or a binary attachment in an email. Four characters for every three bytes, using only 64 safe ones.

The detail that trips people up is anything outside plain English. The browser's own btoa throws on the first accented letter, because it only accepts characters under 256. This encodes the UTF-8 bytes instead, so "café" and an emoji both encode and decode back exactly as they went in. If the value is going into a URL, a cookie or a JSON Web Token, tick URL safe alphabet: + and / become - and _ and the padding is dropped, which is what RFC 4648 calls the URL and filename safe variant.

Remember that encoding grows the data by about a third. That is the price of using a text channel for bytes, and it is why inlining a large image as a data URI is usually a false economy: you save one request but send more bytes, and the browser can no longer cache the image separately from the page. Shrinking the picture first with the image compressor takes far more off the result than the encoding ever adds.

How to encode text as Base64

  1. Type or paste your text. The Base64 appears as you go, nothing to press.
  2. Tick URL safe alphabet for a value that goes into a URL, a cookie or a token.
  3. Drop a file onto the box to get a full data: URI for it, ready for CSS or HTML.
  4. Press Copy to take the result.
  5. Paste Base64 instead and the direction flips on its own, so you get the decoded text.

Common questions about Base64 encoding

Does a file I drop on the box get uploaded?

No. The encoding happens in JavaScript on this page, including for dropped files, so documents and images stay on your own device. Nothing is sent, logged or saved, and the page keeps working with your connection switched off.

Why does my Base64 differ from another tool's?

Almost always the alphabet or the padding. The URL safe variant swaps two characters and usually drops the trailing equals signs, so the same bytes look different. The other common cause is line breaks: some tools wrap the output every 64 or 76 characters for email. Both forms decode to the same bytes.

How do I make a data URI for an image?

Drop the file onto the input box. You get the complete data:image/png;base64,... string including the media type, which is the part people usually have to add by hand. Paste it into a CSS url() or an img src. It works well for a small icon and badly for a photograph.

Can I encode an emoji or a non-English name?

Yes. The text is converted to UTF-8 bytes first, which is what a correct implementation does, so anything you can type encodes and comes back unchanged. Tools that hand the raw string to btoa throw an error instead, which is the bug behind most "invalid character" messages you will find online.

Does Base64 encoding protect anything?

No. It is reversible by anyone with no key at all, so it hides nothing. Encode for transport, and use real encryption if the content needs to stay private. Putting a password through Base64 and treating it as secured is a genuinely common security mistake.

Next

Related tools

All Dev tools