Base64 Encoder and Decoder

Base64 turns bytes into 64 safe text characters, three bytes at a time into four characters, so binary data can travel through systems built for text.

Also called: Base64 converter · Base64 encode/decode

  • Last updated
  • Formula tested against reference values

Your numbers

Action
Alphabet

Result

Result
—

Calculating…

Bytes of text (UTF-8)
—
Characters in result
—

How to use this calculator

  1. Enter or choose action.
  2. Enter or choose alphabet.
  3. Enter or choose text.
  4. The result updates as you type. Use Copy result or Share to keep it.

Method

Take the UTF-8 bytes 3 at a time (24 bits), split into four 6-bit groups, and map each to A–Z, a–z, 0–9, + and / (or - and _). Pad a final partial group with =.

= padding
one = when the last group has 2 bytes, two when it has 1 (omitted in the URL-safe variant)

Worked example

  1. "foo" is bytes 66 6F 6F = 011001 100110 111101 101111 → Z m 9 v.
  2. "bar" is bytes 62 61 72 = 011000 100110 000101 110010 → Y m F y.

"foobar" encodes to Zm9vYmFy (the RFC 4648 test vector).

What the result means

Base64 output is about a third larger than the input. It is an encoding, not encryption: anyone can decode it.

Assumptions and limits

  • Text is converted to bytes as UTF-8, the encoding used by the web.
  • Decoding is limited to results that are valid UTF-8 text; Base64 that contains an image or other binary file cannot be shown as text.

Questions

Is Base64 encryption?

No. It only changes the representation of the data and can be reversed by anyone. Never use it to protect passwords or secrets.

What is the URL-safe variant?

RFC 4648 base64url replaces + with - and / with _ so the result can go in URLs and file names; the = padding is usually dropped.

Sources