Youtilities

Popular

All tools

Base64 Encode & Decode

Encode text or files to Base64 and decode it back. Base64 to image preview, URL-safe option.

Runs in your browser. Nothing is uploaded.

Input
Output
Base64 appears here.

What this does

Encode text or any file to Base64, or decode Base64 back to text. Text is handled as UTF-8, so accents and emoji survive the round trip. Switch direction and the output becomes the new input.

Base64 to image and files

Paste a Base64 string or a data: URL of an image and you get a preview and a download. PNG, JPEG, GIF, WebP, SVG, PDF, and ZIP are recognised from their first bytes; anything else downloads as a file.

URL-safe and padding

URL-safe Base64 swaps + and / for - and _, as used in JWTs and web tokens. Padding adds = at the end to a multiple of four characters; some systems leave it out. Decoding accepts both forms.

Why is Base64 bigger than the original?

Base64 turns every 3 bytes into 4 characters, so the output is about 33% larger than the input, plus up to two = signs of padding. A 30 KB image becomes roughly 40 KB of text, and a 3 MB file about 4 MB. The size of the input and the output is shown above each panel, so you can see the difference for your own file.

When should you use Base64?

Use it when binary data has to travel through something that only accepts text: an image inside a JSON request, an email attachment, a small icon embedded in CSS or HTML, a certificate or key in a config file, or the user:password pair in an HTTP Basic auth header. To show an encoded image in a web page, put data:image/png;base64, (or the right type) in front of the output. Embedding only pays off for small files of a few KB; larger images are better served as normal files that the browser can cache.

Base64 is not encryption

Anyone can decode Base64 in one step, including with this page. It hides nothing, so never use it to protect passwords, API keys or personal data. A Basic auth header, for example, is the password in plain sight unless the connection uses HTTPS.

Why does decoding fail?

"This is not valid base64" appears when the input has characters outside the Base64 alphabet, such as % signs from URL encoding, quotes or commas copied along with the value, or an ellipsis where a log cut the string short. A string whose length leaves one character over after grouping by four is also truncated. Spaces and line breaks are ignored, and a data: prefix is removed for you. If you expected text but see "Binary data", the original was not UTF-8 text (for example UTF-16 or an old Windows encoding) or was a file; download it and open it in a program that can read it.