Base64 Validator

Paste a value to find out whether it is valid Base64 according to the selected standard. Every problem is listed with its exact position, so you can see what is wrong instead of just getting “invalid”.

What makes Base64 valid?

  • Only characters from the alphabet of the chosen standard (for example A–Z a–z 0–9 + /).
  • Correct padding: the length is a multiple of 4 and ends with at most two =. Base64URL and IMAP usually omit padding.
  • No spaces or line breaks, except in MIME (76 characters per line) and PEM (64 characters per line).
  • The length is never 4n+1, because one leftover character cannot represent a full byte.

Validate Base64 in code

// JavaScript
const isBase64 = (s) => /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(s);

# Python
import base64, binascii
def is_base64(s: str) -> bool:
    try:
        base64.b64decode(s, validate=True)
        return True
    except binascii.Error:
        return False

Frequently asked questions

How do I check if a string is Base64?

A valid standard Base64 string contains only A–Z, a–z, 0–9, "+" and "/", has a length that is a multiple of 4, and ends with zero, one or two "=" padding characters.

Can a regular expression validate Base64?

Yes: ^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$ validates standard Base64 without line breaks.

Related tools and guides

Comments (0)

Questions, ideas or a bug in “Base64 Validator”? Leave a comment, rate the tool, or reply to others.

No comments yet. Be the first to share your feedback!

Leave a comment

Rate this tool:
Esc
↑ ↓ move↵ openEsc close