Base64 Encode / Decode

Encode and decode Base64, UTF-8 safe, with URL-safe variant.

About this tool

Convert text to Base64 and back. Handles any Unicode text correctly and supports the URL-safe alphabet (base64url) used in JWTs and URLs.

How to use it

  1. Choose Encode to turn text into Base64, or Decode to turn Base64 back into text.
  2. Paste your input. Unicode text such as accents or emoji is handled correctly.
  3. For tokens and URLs, turn on URL-safe to use - and _ instead of + and /.
  4. Copy the result, or click Swap to reverse the operation.

Questions

Is Base64 encryption?
No. Base64 is an encoding that anyone can reverse instantly. Never use it to hide passwords or secrets.
What is the difference between Base64 and Base64url?
Base64url replaces + with - and / with _ and usually drops the = padding, so the result can be used in URLs and file names. JWTs use Base64url.
Why does decoding fail?
Either the input has characters outside the Base64 alphabet, or it decodes to binary data rather than UTF-8 text, such as an image or a compressed file.
Why is the encoded text longer?
Base64 represents every 3 bytes with 4 characters, so the output is about 33% larger than the input.
What does the = at the end of Base64 mean?
It is padding. Base64 output is always a multiple of four characters, so one = means the last group held two bytes and == means it held one. Padding carries no data, which is why base64url usually drops it. This tool adds missing padding back before decoding.
How do I Base64 encode on the command line?
On Linux and macOS, run printf hello | base64 to get aGVsbG8=. Avoid plain echo, which adds a newline and gives aGVsbG8K instead. To decode, use base64 -d, or base64 -D on older macOS versions. In PowerShell, use [Convert]::ToBase64String with the bytes of your text.
How do I decode a Base64 image or PDF?
This tool decodes to UTF-8 text, so binary data such as a PNG or PDF shows an error instead of a file. Save the Base64 string to a file and run base64 -d input.txt > image.png in a terminal. Strip any data:image/png;base64, prefix first, because it is not part of the encoded data.

What is Base64 encoding and how does it work?

Base64 represents binary data with 64 printable ASCII characters: A–Z, a–z, 0–9, + and /. The standard alphabet is defined in RFC 4648. The encoder reads the input three bytes at a time, splits those 24 bits into four groups of 6 bits, and maps each group to one character. That is how the three bytes of “Man” become “TWFu”. When the input length isn’t a multiple of three, = padding fills the last group.

Base64 exists because many channels were built for text, not raw bytes. Email attachments (MIME), data: URLs in HTML and CSS, HTTP Basic authentication headers, PEM certificates and JSON fields that carry images all rely on it. It is a transport encoding, not compression and not security. Decoding is instant and needs no key, so treat anything you Base64-encode as plain text that anyone can read.

How to decode Base64 to text, and why UTF-8 matters

To decode Base64 online, choose Decode and paste the string. Spaces and line breaks are stripped first, so wrapped output from a PEM file or an email decodes fine. Missing = padding is added back automatically, and the URL-safe characters - and _ are accepted as well, so you don’t need to know which variant you have. The decoded bytes are then read as UTF-8 text.

UTF-8 matters because Base64 encodes bytes, not characters. The browser’s built-in btoa() only accepts Latin-1, so calling it on text with ✓ or an emoji throws an InvalidCharacterError. This tool converts text to UTF-8 bytes first, so accents and emoji round-trip correctly: “é” becomes the two bytes C3 A9 and encodes as “w6k=”. If decoded bytes aren’t valid UTF-8, such as an image or a gzip file, you get an error instead of garbled text.

Base64 vs hex vs URL encoding: which one to use

Base64, hex and percent-encoding all turn data into safe text, but they suit different jobs. Hex uses two characters per byte, so the output doubles in size, yet it is easy to read and standard for hashes and checksums. Base64 uses four characters for every three bytes, about 33% overhead, which makes it the better choice for larger binary payloads such as images, keys or file contents inside JSON.

Percent-encoding, used in URLs, is meant for text with a few reserved characters, not for binary data. If a Base64 value has to go into a URL, query string or file name, use the base64url alphabet instead of percent-encoding + and /. Turn on URL-safe when encoding here: - and _ replace + and /, and the = padding is dropped, which is the exact format JWTs use. For percent-encoding itself, use the URL tool.

Something not working, or a result looks wrong? Report a problem with this tool