OnlineTextLab
Esc

Base64 Encoder / Decoder

Base64 in both directions, for text or any file, with URL-safe and MIME options.

Direction

Encoded

The result appears here as you type.

Runs on your device. Your files and text are not uploaded.

About Base64 Encode Decode

Base64 turns bytes into plain letters and digits so they can pass through something built for text: a JSON field, an email, a data URL, a config value, a Kubernetes secret. When you meet a Base64 string, you usually want to know what it says. When you need to send bytes through a text channel, you need the reverse.

This page does both, and it copes with the mess of real input. Decoding takes the standard alphabet, the URL-safe one, missing padding, line breaks and whole data: URLs without asking which you have. If the bytes turn out not to be text, it says what they look like and lets you download the original file, rather than showing you garbage.

How it works

Text is first converted to UTF-8 bytes, and those bytes are encoded. That is why non-English text and emoji work here, where the browser's own btoa function throws an error on them. Every 3 bytes become 4 characters, so the result is about a third larger than the input. Uploading a file skips the text step and encodes its exact bytes.

Decoding reverses this and then tries strict UTF-8. If that fails, the tool checks the first bytes for the signatures of PNG, JPEG, GIF, PDF, ZIP and gzip. It shows a hex preview and offers a download with the right extension. A length that no encoder can produce gets its own error, because it usually means the string was cut off while copying.

How to use Base64 Encode Decode

  1. Under Direction, pick Encode to Base64 or Decode from Base64.
  2. Type or paste into the box, or press Upload to open a file. Try an example fills in a sample for the current direction.
  3. When encoding, choose any of URL-safe alphabet, Leave off = padding and Wrap at 76 characters. Decoding detects these for itself.
  4. Press Copy or Download. Use as input sends the result back through in the other direction, which is a quick way to check a round trip.

The same text, standard and URL-safe

Input
Héllo wörld! 日本語 🔐
Output
SMOpbGxvIHfDtnJsZCEg5pel5pys6KqeIPCflJA=

With URL-safe and no padding:
SMOpbGxvIHfDtnJsZCEg5pel5pys6KqeIPCflJA

The alphabet difference only shows when + or / would appear. The text a?> encodes to YT8+ in the standard form and YT8- in the URL-safe one.

When it helps

  • Reading a value from a Kubernetes secret or an environment variable
  • Building an Authorization: Basic header from a username and password
  • Turning a small file into a string to embed in JSON or a test fixture
  • Finding out what a mystery Base64 blob in a log or API response really is

Tips for a better result

  • Base64 is not encryption. Anyone can reverse it in seconds, so do not treat encoded values as hidden.
  • Use the URL-safe alphabet for tokens that travel in a URL or filename. JWTs use it with the padding left off.
  • For pictures you want to place in HTML or CSS, Image to Base64 writes the data: URL and the tag for you.

Good to know

  • Files for encoding can be up to 25 MB, since larger strings get too slow to show in a text box.
  • Binary output is only recognized for the six common types above. Anything else comes out as a .bin file with a hex preview.
  • Decoding expects Base64, not other encodings such as Base32 or hex.
  • Decoded text must be valid UTF-8. Text in an older encoding such as Latin-1 is treated as binary, so download it and open it with the right encoding.

Questions people ask

Why does my Base64 end in = signs?

Padding. Output comes in groups of 4 characters, and = fills the last group when the input does not divide evenly by 3 bytes. Many systems accept it either way, and this page decodes both.

What is URL-safe Base64?

The same encoding with - and _ in place of + and /, which have special meanings in URLs. RFC 4648 defines it, and JWTs rely on it.

Why does the same text give a different result in another tool?

Most often the other tool used a different text encoding or included a trailing line break. Command-line echo adds one unless you pass -n, and that changes the output.

When would I wrap at 76 characters?

When producing email or other MIME content, where RFC 2045 limits the line length. Most other uses want one long line, so it is off by default.

What to use next

Learn more

Last reviewed . Read our editorial policy.