Validate Base64 and Base64URL Strings – Free

Paste a string to check that it is well-formed Base64. This Base64 validator applies strict rules for characters, padding, length and trailing bits, and reports the decoded size when the value passes.

How to use the Validate Base64 tool

  1. Paste the string into the Base64 or Base64 data URL box, or select Example to load a valid sample.
  2. Select Validate to run the checks.
  3. If the value is well formed, the Result box shows Valid and the number of decoded bytes.
  4. If it is not, an error message appears under the Result box. Compare the string with the rules below to find the cause.

The rules this Base64 validator applies

Whitespace is ignored and a data URL prefix is removed. What remains must satisfy every rule in this list.

  • Characters: A-Z, a-z, 0-9 and one pair of extras, either + and / or - and _. The two pairs cannot be mixed.
  • Padding: at most two = signs, and only at the very end.
  • With padding, the total length must be a multiple of four.
  • Without padding, the last group may have two, three or four characters, never one.
  • Unused bits in the last data character must be zero.

Unused bits: the check lenient decoders skip

When the data ends with a single byte, it is written as two characters. Two characters hold 12 bits, the byte needs 8, and the remaining 4 must be zero. When the data ends with two bytes, three characters hold 18 bits and the last 2 must be zero. RFC 4648 section 3.5 describes this as canonical encoding.

QQ== is the canonical encoding of the letter A. QR== sets one of the spare bits. Many decoders accept both and return A for each, which means two different strings stand for the same data. That is a problem wherever encoded values are compared, signed or used as keys, so this validator rejects the second form.

QQ==   Valid · 1 decoded bytes
QR==   Enter valid Base64 or Base64URL data.
QUI=   Valid · 2 decoded bytes
QUJ=   Enter valid Base64 or Base64URL data.

What a Valid result does and does not tell you

Valid means the string is well formed and decodes to the stated number of bytes. It does not mean the string was meant as Base64. The word test passes, because four letters from the alphabet are a legal group.

The tool is stricter than many decoders about spare bits and mixed alphabets, and more relaxed about padding and whitespace. A value that passes here can still be refused by a library that demands = signs or forbids line breaks. A failure produces one general message, Enter valid Base64 or Base64URL data, without naming the broken rule.

Common reasons validation fails

Check these everyday causes first, before you look for anything more exotic.

  • Quotes or a trailing comma copied along with the value from JSON or source code.
  • Percent escapes such as %3D or %2B from a URL that was never decoded.
  • A complete JWT. The dots between its three segments are not Base64 characters, so validate each segment separately.
  • A string cut off in a log, leaving one character in the final group.
  • An = sign in the middle, left over from joining two encoded values.

Frequently asked questions

What makes a Base64 string invalid?

A character outside the alphabet, both alphabets used together, padding in the wrong place or of the wrong length, a length that leaves one lone character, or non-zero spare bits at the end. Any one of these fails validation.

Is Base64 without padding valid?

In this validator, yes. Unpadded input is accepted as long as the last group has two or three characters. Whether your target system agrees depends on its decoder, since some require the = signs.

Can I validate a JWT with this tool?

Not as a whole. Paste the header, payload and signature one at a time, without the dots. Each segment is unpadded Base64URL and should pass. Passing says nothing about whether the signature is correct.

Is there a regular expression for Base64?

A common pattern for padded standard Base64 is ^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$. It checks characters and padding only. It does not catch non-zero spare bits, which this validator does.

How is Validate Base64 different from Verify Base64?

Validate checks syntax: is this a well-formed encoding. Verify decodes the value and computes a SHA-256 hash of the bytes, which tells you whether the content is the content you expected.

Related tools