Home/Developer Tools/Base64 Encoder & Decoder
🔐

Base64 Encoder & Decoder

FREE

Encode and decode text in Base64 format

Free · No sign-up required
Loading...

What Base64 is and what it isn't

Base64 is a way to encode arbitrary bytes — including binary data like images or PDFs — using only 64 printable ASCII characters. It is defined in RFC 4648. Base64 is an encoding, not encryption: there is no key and anyone can decode the result. Its purpose is to transport binary data through systems (email headers, URL parameters, JSON values) that only safely handle text.

How the encoding works

Base64 takes input three bytes at a time (24 bits) and splits it into four groups of 6 bits. Each 6-bit group becomes one of 64 characters: A–Z, a–z, 0–9, +, /. If the input length is not a multiple of three, the output is padded with = signs so the length is always a multiple of four.

The encoded output is always 33% larger than the input — every 3 input bytes produce 4 output characters.

A worked example

Encoding the three ASCII bytes for "Man":

  • M = 77 = 01001101
  • a = 97 = 01100001
  • n = 110 = 01101110
  • Concatenated: 010011010110000101101110
  • Split into 6-bit groups: 010011 010110 000101 101110
  • Values: 19, 22, 5, 46
  • Mapped to alphabet: TWFu

So "Man" encoded is "TWFu". Three bytes in, four characters out, no padding needed.

Standard, URL-safe, and other variants

VariantAlphabetPaddingUse case
Standard (RFC 4648 §4)A–Z a–z 0–9 + /RequiredMIME, general data transport
URL-safe (RFC 4648 §5)A–Z a–z 0–9 - _OptionalURLs, file names, JWT
Base64url (no pad)A–Z a–z 0–9 - _StrippedJWT, JSON Web Signatures
Base32A–Z 2–7RequiredHuman-readable strings, OTP secrets
Base58Custom 58-charNoneBitcoin addresses, IPFS

The two characters that change between variants — + vs - and / vs _ — are chosen so that the URL-safe alphabet survives URL encoding without escaping.

When to use Base64

  • Embedding images in CSS or HTML via data: URIs to avoid an extra HTTP request.
  • Storing binary blobs in JSON (which natively has no binary type).
  • Email attachments — MIME wraps every binary attachment in Base64.
  • JWT tokens use Base64url for headers, payloads, and signatures.
  • HTTP Basic Auth encodes username:password as Base64.
  • Cryptographic key fingerprints (e.g. SSH key files contain Base64-encoded blobs).

When NOT to use Base64

  • For secrets in URLs. Base64 looks scrambled but is fully reversible — anyone can decode an exposed token.
  • For very large files in JSON. 33% size overhead plus the JSON-string escape overhead make it inefficient compared to a separate binary endpoint.
  • Inside other Base64. Nested encoding makes debugging painful and doubles the size overhead.
  • As password hashing. A Base64-encoded SHA-256 is still just SHA-256 — use a slow KDF like Argon2id or bcrypt for passwords.

Size and performance

The 4:3 expansion ratio is a hard limit — every Base64 string is exactly ceil(input_bytes / 3) × 4 characters long. With line breaks every 76 characters (MIME convention) the overhead climbs to about 37%. For very small inputs (under 4 KB), data-URI embedding saves an HTTP round-trip even with the overhead. For large assets, prefer a separate request and let the browser cache and compress it.

Frequently asked questions

Is Base64 encryption?

No. Base64 is reversible by anyone — no key is involved. Do not use it to protect secrets. Use AES-GCM or similar for confidentiality.

Why does my Base64 string end with one or two equals signs?

Padding. Standard Base64 requires the output length to be a multiple of four. The last group is padded with one or two = signs when the input is not a multiple of three bytes.

What is the difference between Base64 and Base64url?

Base64url replaces the two URL-unsafe characters (+ and /) with - and _ respectively, and often omits padding. It can be embedded directly in URL parameters without escaping.

Can I encode UTF-8 text in Base64?

Yes — encode the UTF-8 byte representation of the string. The decoder gets the same bytes back and decodes them as UTF-8. Be careful not to encode the JavaScript UTF-16 representation directly; convert to UTF-8 bytes first.

How does Base64 affect image quality?

Not at all. Base64 is lossless — encoding and then decoding gives back the exact original bytes. The only cost is a ~33% size increase in the transport.

How can I decode a Base64 string by hand?

Look up each character's value (A=0, B=1, ..., /=63), concatenate the 6-bit values, then split into 8-bit bytes. Padding signs are dropped before processing.
Ad
📢Advertisement

More tools in this category

📋
JSON Tools
View tree, format, validate and minify JSON
🌈
Color Code Converter
Convert between HEX, RGB, RGBA, CMYK, HSV and HSL