StringMash.com

Base64 encode and decode

Encode text to Base64 or decode it back, with URL-safe and MIME variants.

Conversion
12 characters
Updates as you type
16 characters

Show the steps
  1. Turn the text into bytes with UTF-8, eight bits each.
  2. Take the bytes three at a time: 24 bits, cut into four groups of 6. Each group is a number from 0 to 63, and that number picks a character from A–Z, a–z, 0–9 and two symbols.
  3. Hel: 01001000 01100101 01101100 → 010010 000110 010101 101100 → 18 6 21 44 → SGVs
  4. lo,: 01101100 01101111 00101100 → 011011 000110 111100 101100 → 27 6 60 44 → bG8s
  5. wo: 00100000 01110111 01101111 → 001000 000111 011101 101111 → 8 7 29 47 → IHdv
  6. The other 1 group follow the same rule.
Printable chart

Using the Base64 encoder

Type or paste on the left, read the encoded text on the right. Swap the boxes to decode, or go to the decoder if that's the job.

Character set decides how your text becomes bytes before encoding. Leave it on UTF-8 unless you know the text came from an older system. Variant picks the output alphabet: Standard, URL-safe for anything headed into a web address, or MIME, which wraps at 76 characters the way email expects.

What is Base64?

Base64 reads three bytes at a time and writes them as four characters from a 64-character alphabet. Three bytes is 24 bits; four characters carry six bits each. The arithmetic is exact, and the output is a third longer than the input.

When the input doesn't divide by three, the last group is padded and the output ends in one or two = signs. That padding is the easiest way to recognise Base64 on sight, and a length that isn't a multiple of four means something was cut off.

64 CHARACTERS

The Base64 alphabet

CharactersValues
A–Z0–25
a–z26–51
0–952–61
+62
/63
=padding

Why it exists

Email was built for text, and for years it was built for seven-bit text. Push raw bytes through it and gateways would strip the eighth bit, rewrite line endings, or read a stray byte as a control code. Anything that wasn't plain English arrived broken.

Base64 was the workaround, and MIME standardised it for attachments in 1992. Every photo you've ever emailed made the trip this way, a third larger than it sat on disk.

It never left. Data URIs embed images in stylesheets with it, JSON Web Tokens use the URL-safe variant for each of their three parts, and keys and certificates get passed around as Base64 because they paste into a terminal without breaking.

Base64 vs hex

Both write bytes as text, at different costs. Hex uses two characters per byte, doubling the size. Base64 packs three bytes into four characters, about a third bigger. Hello is 5 bytes: 10 characters in hex, 8 in Base64 with its padding.

Base64
SGVsbG8=8 characters, 8 bytes
Hex
48 65 6c 6c 6f14 characters, 14 bytes

Related conversions

Base64, hexadecimal and binary write the same bytes at different densities. Binary takes eight digits for every byte, and Base64 gets that down to about 1.33 characters, with hex in between at two.

For the number behind each character rather than the bytes behind the text, see character codes and Unicode code points.

Questions

Is Base64 encryption?

No. Anyone can decode it, and there's no key to keep secret.

What is URL-safe Base64?

A variant that swaps + for - and / for _, so the result survives a web address without extra escaping. JSON Web Tokens use it.

Why is my output a third bigger?

Four characters carry three bytes. That overhead buys safe passage through systems that only handle text.

Why does my decoded text look garbled?

The bytes probably weren't text. Base64 often carries images, PDFs or keys, and those read as noise.

What's the difference between Base64 and Base64URL?

Base64URL swaps + and / for - and _, which are safe in URLs and file names. Set Variant to URL-safe above to get it. This tool keeps the = padding. JWTs leave it off, so delete any = signs at the end if you need that form.

Is Base64 encryption?

No. Anyone can decode it, with no key. [Encoding vs encryption vs hashing](/encoding-vs-encryption-vs-hashing) explains the difference.

Sources

Added . Last updated and reviewed . What's new