Skip to content
thecalculatorstudio

Base64 Encoder and Decoder

Type or paste text to encode it as base64, or paste base64 to decode it. Choose the standard or URL-safe alphabet. It all happens in your browser and nothing is sent or saved.

Last reviewed

Everything happens in your browser. The text is not sent anywhere or saved. Text is encoded and decoded as UTF-8.

Base64

Zm9vYmFy

8 characters

Base64 is an encoding, not encryption. Anyone can decode it, so it hides nothing.

What base64 does

Computers move data as bytes, but many formats, such as email, JSON, XML and URLs, can only carry plain text safely. Base64 bridges the gap by writing any bytes with 64 text characters. RFC 4648 defines the standard alphabet: the capital letters A to Z (values 0 to 25), the lower-case letters a to z (26 to 51), the digits 0 to 9 (52 to 61), then + (62) and / (63).

The method:

  1. Take the bytes in groups of 3, which is 24 bits.
  2. Split the 24 bits into four groups of 6 bits.
  3. Write each 6-bit value as the character with that number.

So 3 bytes become 4 characters. If the data ends with only 1 or 2 bytes, the output is padded with = to a multiple of 4 characters. That is why base64 is about one third longer than the original.

Test values from the RFC

RFC 4648 section 10 gives these, which the tool reproduces exactly:

Text Base64
f Zg==
fo Zm8=
foo Zm9v
foob Zm9vYg==
fooba Zm9vYmE=
foobar Zm9vYmFy

foo is the bytes 0x66, 0x6F, 0x6F, which is the 24 bits 011001 100110 111101 101111. Those four 6-bit values are 25, 38, 61 and 47, which are the characters Z, m, 9 and v.

URL-safe base64

The characters + and / have meaning in URLs and filenames. RFC 4648 section 5 describes an alphabet that is identical except that - replaces + and _ replaces /. It is often written without the = padding. JSON Web Tokens use this form. The encoder offers it as an option, and the decoder accepts either alphabet and missing padding.

Text and UTF-8

Base64 encodes bytes, not letters. The tool first converts your text to bytes with UTF-8, so a plain English letter is one byte, an accented letter such as é two, and an emoji four. For example é is the bytes C3 A9, which encodes to w6k=. When you decode, the bytes are read as UTF-8 text. If they are not valid UTF-8, for example when you decode an image, the tool shows them as hex.

Is it secure?

No. Base64 is a reversible encoding with no key. It makes data look unreadable at a glance, but anyone can decode it in a second. Do not use it to protect passwords or secrets. The text you type here is processed in your browser and is not sent anywhere or saved.

Common mistakes

  • Treating base64 as encryption.
  • Mixing the two alphabets. A string with both + or / and - or _ is not valid.
  • Losing the padding in the middle. The = signs belong at the end only.
  • Decoding as text something that is binary. A decoded image is not readable text.
  • Adding line breaks. Whitespace is ignored when decoding, but some systems insert breaks every 76 characters.

To decode a token with base64url parts, see the JWT decoder. For percent-encoding in URLs use the URL encoder and decoder, and for fingerprints of data the hash generator.

How it is calculated

Encoding and decoding are done by exact bit arithmetic in the page, without relying on the browser’s btoa or atob, so UTF-8 text and every byte value are handled.

Frequently asked questions

What is base64?

A way to write any bytes using 64 safe text characters: A–Z, a–z, 0–9, + and /. Every 3 bytes become 4 characters, which is why base64 text is about a third longer than the data. It is used to put binary data into text formats such as email, JSON and URLs.

Is base64 encryption?

No. It is a reversible encoding with no key, so anyone can decode it. Never rely on base64 to hide a password or a secret.

What is the equals sign at the end?

Padding. Base64 works in groups of 3 bytes. When the data ends with 1 or 2 spare bytes, the output is padded with = or == to make a multiple of 4 characters. For example, the single letter f encodes to Zg==.

What is URL-safe base64?

The same encoding with - in place of + and _ in place of /, so it can sit in a URL or filename without escaping. RFC 4648 section 5 defines it, and it often leaves out the padding. JSON Web Tokens use it.

How are accented letters and emoji handled?

The text is first turned into bytes with UTF-8, then those bytes are encoded. So é becomes two bytes and an emoji four. Decoding reverses it, and if the bytes are not valid UTF-8 the tool shows them as hex instead.

Why does decoding say the length is wrong?

A valid base64 string never leaves exactly one character over after splitting into groups of 4, because one character carries only 6 bits and a byte needs 8. If your string is cut short, some characters were lost.

Related calculators

Sources