Skip to content
FreeToolsKit.app

Text & Writing guide

Base64 Is Not Encryption: How to Encode, Decode and Check Base64

8 min read · Updated 20 November 2026 · Uses Base64 Encoder & Decoder

Quick answer

Base64 rewrites any bytes, such as text, an image or another file, using 64 characters: A–Z, a–z, 0–9, + and /, with = as padding at the end. Every 3 bytes become 4 characters, so the result is about a third bigger than the original. Base64 is an encoding, not encryption. There's no key, and anyone can turn it back into the original in seconds.

When decoding fails, check for these four causes:

  • Extra characters: line breaks from email wrapping, or a data: prefix pasted along with the Base64.
  • The wrong alphabet: URL-safe Base64 (- and _) decoded as standard Base64 (+ and /), or the reverse.
  • Wrong padding: too many or too few =, or = in the middle because two values were joined.
  • A cut-off value: part of the string is missing.

In FreeToolsKit's Base64 Encoder & Decoder:

  1. Choose Encode or Decode.
  2. Under Alphabet, pick Standard Base64 (+ /) or URL-safe Base64URL (- _). When encoding, tick or clear Add = padding at the end.
  3. Type text, choose Local file, or paste the Base64. Then press Encode, Encode file or Decode.
Base64 Encoder & DecoderFree to use · No account required · Converted in your browserOpen Base64 Encoder & Decoder

How Base64 works

Base64 takes the input 3 bytes (24 bits) at a time, splits them into four 6-bit groups and writes each group as one of 64 characters (IETF: RFC 4648, section 4). When the input doesn't divide evenly by 3, the last group is short. The encoder then adds one or two = so the length is a multiple of 4.

Text has to become bytes first. The usual choice is UTF-8, where a character takes "1 to 4 octets" (IETF: RFC 3629). The browser's built-in btoa() throws an error for any character that doesn't fit in a single byte. MDN's advice is to convert the string "to its constituent bytes in UTF-8, and then encode the bytes" (MDN: btoa()). The tool does this for you: its text box says the text is "Encoded as UTF-8, exactly as typed (no normalization)".

The tested example: one text, four outputs

To show what changes between the options, this guide uses a short made-up note: Café, £5 ✓ (paid?). It's 18 characters, but 22 bytes in UTF-8, because é and £ take two bytes each and ✓ takes three.

The text was typed into Text to encode and encoded four times, once for each combination of Alphabet and Add = padding at the end. Every run reported "22 bytes of UTF-8 text":

  • Standard Base64 (+ /), padded (the default): Q2Fmw6ksIMKjNSDinJMgKHBhaWQ/KQ==, 32 characters.
  • Standard, unpadded: the same without the final ==, 30 characters.
  • URL-safe Base64URL (- _), unpadded: Q2Fmw6ksIMKjNSDinJMgKHBhaWQ_KQ, 30 characters. The tool leaves padding off by default for this alphabet.
  • URL-safe, padded: the same with == added, 32 characters.

Python's base64 module gave the same results from the same 22 bytes. Decoding any of them in the tool, with the matching alphabet, returned Café, £5 ✓ (paid?) exactly.

What differs between the alphabets. Only character 28 changed: / in standard Base64, _ in Base64URL. The URL-safe alphabet swaps + and / for - and _, so output with neither is the same in both. RFC 4648 also notes that padding "is typically percent-encoded when used in an URI" and can be skipped when the length is known (section 5). JSON Web Tokens use Base64URL "with all trailing '=' characters omitted" (IETF: RFC 7515).

Why the alphabet matters in links. A + from standard Base64 can turn into a space in a query string, because URLSearchParams "interprets plus signs (+) as spaces" (MDN: URLSearchParams). Use Base64URL for anything that goes into a URL or a file name.

Why Base64 is about a third bigger

Four characters for every three bytes means the padded length is 4 × (n ÷ 3, rounded up), where n is the number of bytes. Without padding, the last group drops its one or two =. The MIME standard says encoded data is "consistently only about 33 percent larger" (IETF: RFC 2045). MDN adds that the exact increase depends on the length "modulo 3, and whether padding characters are used" (MDN: Base64).

The test measured three inputs, all with Standard Base64 (+ /) and padding on:

  • The 22-byte note: 32 characters, 45% bigger. Short inputs grow by more than a third, because the last group is rounded up to 4 characters.
  • A 167-byte, 24 × 24 pixel PNG icon: 224 characters, 34% bigger. Under Local file, the tool showed "Base64 length 224 characters" before encoding.
  • A 3,000-byte file of fixed random bytes: 4,000 characters, exactly a third bigger, because 3,000 divides by 3.

Each Base64 character is one byte when saved as plain text. The downloaded base64.txt files were 224 and 4,000 bytes.

Wrapping and prefixes add more. Email wraps Base64 in lines of "no more than 76 characters" (IETF: RFC 2045). Wrapping the 4,000 characters that way, with email-style line endings, gave 4,106 characters (Python's base64.encodebytes), about 37% over the original file. A data URL also adds its prefix, such as data:image/png;base64,, which is 22 characters.

Base64 is not encryption

To show how little Base64 hides, the guide encoded a made-up password, BlueHeron-2026!. The tool returned Qmx1ZUhlcm9uLTIwMjYh. Pasting that into Decode gave back BlueHeron-2026! at once, with no key.

RFC 4648 says Base64 "visually hides otherwise easily recognized information, such as passwords, but does not provide any computational confidentiality". It adds that this "has been known to cause security incidents" when people share protocol logs without realising a password is in them (IETF: RFC 4648, section 12). MITRE lists it as a known weakness: obscuring a password with an encoding "such as base64 encoding" "does not adequately protect the password" (MITRE: CWE-261).

So treat any Base64 you see in a log, a config file or a URL as readable. If a value has to stay secret, it needs real protection, such as encryption with a key that's kept apart from the data. A different encoding won't do it.

Why decoding fails, and how to fix each error

The tool's decoder is strict. Under the input box it says: "Decoding is strict: spaces, line breaks, mixed alphabets and wrong padding are reported rather than skipped." Each problem below was pasted into Base64 to decode with Standard Base64 (+ /) selected. Each item quotes the message, then a fix that was tested by decoding again.

  1. Line breaks from email wrapping. The icon's Base64, wrapped at 76 characters, gave "Spaces, tabs and line breaks aren't allowed (found U+000A at position 77). Remove them and try again." Position 77 is the first character after the first full line. Fix: join the lines into one. After that, the tool showed Decoded binary data, 167 bytes.
  2. A data URL. The icon as data:image/png;base64, followed by its Base64 gave 'This is a data URL ("data:…;base64,"). Paste only the Base64 part after the comma.' A data URL has the form data:[<media-type>][;base64],<data> (MDN: data: URLs). Fix: delete everything up to and including the first comma.
  3. The wrong alphabet. The URL-safe version of the note gave '"_" at position 28 belongs to URL-safe Base64. Choose URL-safe Base64, or use + and / instead of - and _.' Fix: choose URL-safe Base64URL (- _). The note then decoded correctly. The opposite mistake gets the matching message, naming / and standard Base64.
  4. Both alphabets in one string. The icon's Base64 with only + changed to -, a half-finished conversion, failed under both alphabets. Standard stopped at the - (position 134). URL-safe stopped at the first / (position 64). Fix: convert consistently, so - becomes + and _ becomes /, or go back to the original value.
  5. Wrong padding. The note's Base64 with one = instead of two gave 'This needs exactly 2 "=" at the end for padding, or none; it has 1.' Fix: remove the =, or add the missing one.
  6. Two values joined. The note's padded Base64 followed by the password's gave "Padding (=) may only appear at the very end, but data follows it at position 33." An = in the middle is a sign that two values were joined. Fix: split them and decode each one separately.
  7. A cut-off value. The first 17 characters of the note gave "17 Base64 characters is not a valid length (it leaves one character over, which can't encode a byte). The text may be cut off or have an extra character." Fix: copy the whole value again from its source.
  8. An edited last character. QR== gave a message that the last character "sets bits that don't belong to any byte", so it "isn't a canonical Base64 encoding". RFC 4648 lets decoders reject this, because otherwise "multiple base-encoded strings can be decoded to the same binary data" (section 3.5). Here QR== and the correct QQ== would both mean the letter A.

The decoded icon couldn't be shown as text, so the tool offered Download bytes (.bin). The file it saved, decoded.bin, was byte-for-byte the original PNG. Rename it with the right extension, here .png, before you open it.

Why the same string works somewhere else

Decoders follow different rules, so a string can fail here and decode elsewhere. RFC 4648 says decoders "MUST reject" characters outside the alphabet unless the format using Base64 says otherwise, as MIME does (IETF: RFC 4648, section 3.3). MIME says line breaks and other characters "must be ignored by decoding software" (IETF: RFC 2045).

The same inputs were also given to two lenient decoders:

  • The browser's atob(). It follows the "forgiving-base64 decode" steps, which start by removing all ASCII whitespace (WHATWG: Infra Standard). In Chromium it decoded the email-wrapped icon. It threw InvalidCharacterError for the data URL, the URL-safe and mixed strings, the wrong padding, the joined values and the cut-off value. It accepted QR==.
  • Python's base64.b64decode. By default, characters outside the alphabet are "discarded prior to the padding check" (Python documentation: base64). Python 3.13 decoded the wrapped icon. For the data URL, it reported only "Incorrect padding", which doesn't point at the real problem. With validate=True, the wrapped icon failed with "Only base64 data is allowed".

Lenient isn't wrong, but RFC 4648 warns that ignored characters can carry hidden data or "avoid a string equality comparison" (section 12). If a value matters, use the strict message to see what was in the string, and clean it before you use it.

Before you rely on a decoded value

  1. Alphabet: you chose the alphabet the value was made with. If it came from a URL, a file name or a JSON Web Token, try URL-safe Base64URL (- _) first.
  2. Only the Base64: you removed line breaks, spaces and any data: prefix.
  3. The result type: Decoded text means valid UTF-8 text. Decoded binary data means a file or other bytes, which you download and open with the right program.
  4. Secrecy: you're treating the value as readable by anyone, because Base64 never protects it.