Base64 Encode / Decode

Encode and decode Base64 strings instantly

What is Base64?

Base64 is a binary-to-text encoding defined in RFC 4648. It takes arbitrary bytes and represents them with 64 printable ASCII characters: the uppercase letters A-Z, the lowercase letters a-z, the digits 0-9, and two extra symbols, + and /. A 65th character, =, is used as padding at the end.

The point is not to hide data but to make it transportable. Many systems were built to carry text and break on raw binary: email servers that strip the 8th bit, JSON and XML parsers that reject control characters, HTTP headers that cannot contain newlines. Base64 turns any file or byte sequence into a string those systems pass through untouched. On the other side, decoding returns the exact original bytes.

How Base64 Encoding Works

Base64 works on groups of 3 bytes (24 bits) at a time and splits each group into four 6-bit numbers. Each 6-bit number (0-63) is an index into the alphabet A-Z a-z 0-9 + /.

Take the word Man:

Man
ASCII7797110
Bits010011010110000101101110

Regrouped into 6-bit chunks: 010011 010110 000101 101110 → 19, 22, 5, 46 → TWFu.

When the input length is not a multiple of 3, the last group is short. The encoder pads it with zero bits and adds = characters to show how many bytes were missing:

  • Hi (2 bytes) → SGk= (one =)
  • H (1 byte) → SA== (two =)

That is why a Base64 string ends with at most two = signs, and why its padded length is always a multiple of 4. It is also where the 33% size overhead comes from: 3 bytes in, 4 characters out.

How to Use This Tool

  1. Paste text or a Base64 string into the input box.
  2. Click Encode to turn text into Base64, or Decode to turn Base64 back into text. Ctrl+Enter runs whichever button is highlighted.
  3. Copy the result with the Copy button or Ctrl+Shift+C. Ctrl+L clears the input.

As you type, the tool looks at the input. If it is clearly Base64 (only Base64 characters, a valid length, longer than 10 characters, or a data:...;base64, prefix), Decode becomes the highlighted action. If it contains spaces or punctuation that Base64 never uses, Encode is highlighted. You can always click either button yourself.

Encoding converts your text to UTF-8 first, so accented letters, Cyrillic, CJK and emoji all round-trip correctly. Tick URL-safe to get Base64url output (- and _, no padding) for URLs, cookies, filenames and JWT segments.

Decoding is deliberately forgiving about the formats people actually paste:

  • standard Base64 and URL-safe Base64url, even mixed;
  • missing = padding;
  • line breaks every 64 or 76 characters, as in PEM files and email;
  • full data URIs such as data:image/png;base64,iVBORw0..., where the prefix is stripped automatically.

If the decoded bytes are valid UTF-8, you see the text. If they are not, for example because the Base64 contained an image or a gzip stream, you get the byte count, a file-type hint (PNG, JPEG, GIF, PDF, ZIP, gzip) and a hex dump instead of a screen of replacement characters. To turn a Base64 image back into a picture, use the Base64 Image Encoder.

Base64 vs Base64url

Standard Base64’s + and / have special meanings in URLs (+ can be read as a space, / is a path separator), and = separates query parameters. RFC 4648 therefore defines a URL- and filename-safe variant:

Standard Base64Base64url
Characters 62 and 63+ and /- and _
Padding= requiredusually omitted
Used byMIME email, PEM keys, data URIs, HTTP Basic authJWT, WebAuthn, OAuth PKCE, URL parameters

If a decoder rejects a string containing - or _, it is Base64url. Swap the two characters back (or use a decoder that accepts both, like this one) and add padding until the length is a multiple of 4.

Where You’ll Meet Base64

  • Data URIs: small images and fonts inlined in HTML or CSS, data:image/svg+xml;base64,....
  • HTTP Basic authentication: the header Authorization: Basic dXNlcjpwYXNz is just user:pass in Base64. Anyone who sees the header can read the password, which is why Basic auth is only acceptable over HTTPS.
  • JSON Web Tokens: the header and payload of a JWT are Base64url-encoded JSON. Decoding a single segment shows the claims; the JWT Decoder splits and formats all three parts at once.
  • Email attachments: MIME encodes attachments in Base64, wrapped at 76 characters per line.
  • Kubernetes Secrets: values under data: in a Secret manifest are Base64-encoded, not encrypted.
  • PEM certificates and keys: everything between -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- is Base64-encoded DER.
  • APIs: file uploads, image generation results and binary blobs are often returned as Base64 strings inside JSON.

Common Base64 Decode Errors

“Invalid character”: the string contains something outside the Base64 alphabet. Common culprits are a stray quote or comma copied from JSON, a %3D that is really a URL-encoded = (run it through the URL decoder first), or a . because the input is actually a JWT.

“Invalid length”: after removing padding, a valid Base64 string can never have a length of 4n+1 characters. This almost always means the value was truncated when it was copied, for example cut off by a log line limit or a terminal width.

Padding in the middle: an = followed by more characters usually means two Base64 strings were concatenated. Decode them separately.

Garbled text (mojibake): if the output looks like é where you expected é, the original text was encoded with a different character set, such as Windows-1252 or UTF-16, before it was Base64-encoded. If the output shows a hex dump, the data was never text in the first place.

btoa() “characters outside of the Latin1 range”: a JavaScript-specific error. btoa() only accepts one-byte characters. Encode the string to UTF-8 bytes first (see below).

Encoding and Decoding Base64 in Code

JavaScript (browser), with UTF-8 handled correctly:

const bytes = new TextEncoder().encode('héllo ✓');
const b64 = btoa(String.fromCharCode(...bytes));            // "aMOpbGxvIOKckw=="
const text = new TextDecoder().decode(
  Uint8Array.from(atob(b64), c => c.charCodeAt(0))
);

Newer browsers also ship Uint8Array.fromBase64() and bytes.toBase64(), which accept an { alphabet: "base64url" } option.

Node.js: Buffer.from('hello').toString('base64') and Buffer.from(b64, 'base64').toString('utf8'). Use 'base64url' for the URL-safe variant.

Python: base64.b64encode(b'hello'), base64.b64decode(s), and base64.urlsafe_b64encode() / urlsafe_b64decode() for Base64url.

Command line: echo -n 'hello' | base64 encodes and echo 'aGVsbG8=' | base64 -d decodes (older macOS versions use -D). Leave out -n and the trailing newline is encoded too: aGVsbG8K instead of aGVsbG8=, one of the most common “why doesn’t my Base64 match” surprises.

Base64 Is Not Encryption

Base64 has no key and no secret. It is as easy to reverse as it is to apply, and tools like this one do it instantly. Treat a Base64-encoded password, API token or Kubernetes Secret as plain text. If data needs to stay confidential, encrypt it. If you need a fingerprint to check integrity, use a hash function. Base64 only solves one problem: getting bytes through a text-only channel intact.

Frequently Asked Questions

What is Base64 encoding?

Base64 is a binary-to-text encoding that represents any bytes using 64 printable ASCII characters (A-Z, a-z, 0-9, + and /), with = as padding. It lets binary data travel safely through systems that only handle text, such as JSON, XML, HTML, email and HTTP headers.

How do I decode a Base64 string?

Paste the string into the input box and click Decode (or press Ctrl+Enter when Decode is highlighted). The tool accepts standard and URL-safe Base64, strings with or without = padding, strings broken across lines, and full data: URIs. If the decoded bytes are not UTF-8 text, you get a hex dump and a file-type hint instead of garbled characters.

Why does my Base64 decode to garbled characters?

Either the original data was binary (an image, a ZIP file, a compressed payload) rather than text, or the text was encoded in a different character set such as Windows-1252 or UTF-16 before it was Base64-encoded. This tool decodes text as UTF-8 and switches to a hex dump when the bytes are not valid UTF-8, so you can see which case you have.

What is the difference between Base64 and Base64url?

Base64url (RFC 4648 section 5) replaces + with - and / with _ so the result is safe in URLs and filenames, and it usually drops the = padding. JWTs, WebAuthn and many web APIs use it. Tick URL-safe to produce Base64url; the decoder accepts both alphabets automatically.

Does Base64 increase data size?

Yes, by about 33%. Every 3 input bytes become 4 output characters, so 300 KB of binary data becomes roughly 400 KB of Base64. MIME email adds a line break every 76 characters, which pushes the overhead slightly higher.

Is Base64 encryption?

No. Base64 is a reversible encoding with no key, so anyone can decode it in one step. A password or API key that is only Base64-encoded is effectively plain text. Use real encryption (AES, or TLS in transit) to protect data, and a hash function such as bcrypt or Argon2 for stored passwords.

Why does JavaScript btoa() fail with 'characters outside of the Latin1 range'?

btoa() only accepts strings where every character is a single byte (code points 0-255). Emoji, Cyrillic, CJK and other non-Latin-1 text must first be converted to UTF-8 bytes with TextEncoder, and those bytes passed to btoa(). This tool does that conversion for you, so any Unicode text encodes correctly.

Is my data safe with this tool?

Yes. Encoding and decoding run entirely in your browser with JavaScript. Nothing you paste is uploaded or sent to any server, so it is safe to decode tokens, config values and credentials here.