Base64 Validator.
Paste a string and instantly see whether it parses as valid Base64.
In permissive (default) mode, we accept whitespace, URL-safe variants (-, _), and tolerate missing padding. In strict mode, the input must be exactly [A-Za-z0-9+/] followed by 0–2 = padding characters, with length divisible by 4.
Choose permissive mode (handles whitespace, URL-safe variants, missing padding) or strict RFC-4648 §4 compliance.
Updated 9 November 2026
A string is valid Base64 if it uses only A–Z, a–z, 0–9, + and /, its length is a multiple of 4, and it ends with at most two = padding characters. URL-safe Base64 swaps + and / for - and _ and often drops the padding. Paste your string above to check it in strict or permissive mode.
Base64 validity rules.
These are the rules from RFC 4648, the standard that defines Base64. Strict mode in the validator above applies all of them; permissive mode also accepts whitespace, URL-safe characters and missing padding.
The 65 allowed characters
| Values | Standard alphabet (§4) | URL-safe alphabet (§5) |
|---|---|---|
| 0–25 | A–Z | A–Z |
| 26–51 | a–z | a–z |
| 52–61 | 0–9 | 0–9 |
| 62 | + | - |
| 63 | / | _ |
| Padding | = (only at the end, 0–2 of them) | = or omitted |
Length and padding
Base64 turns every 3 bytes into 4 characters, so a padded string's length is always a multiple of 4. The encoded length for n bytes is 4 × ceil(n / 3). The padding depends on what's left over:
| Original bytes mod 3 | Ends with | Example |
|---|---|---|
| 0 | no = | TWFu = “Man” |
| 2 | = | TWE= = “Ma” |
| 1 | == | TQ== = “M” |
An unpadded string whose length leaves a remainder of 1 when divided by 4 can never be valid, because one leftover character can't carry a whole byte. Work out lengths with the padding calculator.
A strict regular expression
This matches standard, padded Base64 exactly (RFC 4648 §4). An empty string also matches, which is correct: it's the encoding of zero bytes.
^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$
For URL-safe Base64 without padding, use ^[A-Za-z0-9_-]*$ and also reject lengths where length % 4 == 1.
Why is my string invalid? Six common causes
- Line breaks or spaces. Email (MIME) wraps Base64 at 76 characters, and copy-paste adds spaces. Strict decoders reject them; remove all whitespace first.
- URL-safe characters in a standard decoder.
-and_come from JWTs and URLs. Replace them with+and/, or use a URL-safe decoder. - Missing padding. JWTs and many APIs strip the
=. Add=until the length is a multiple of 4. - A data URI prefix.
data:image/png;base64,isn't Base64. Strip everything up to and including the comma. - JSON escaping. Strings copied from JSON can contain
\n,\r\nor\/. Parse the JSON (or unescape) before decoding. - Truncation. Logs, terminals and database columns often cut long values. A length with remainder 1 mod 4, or a decoded file that won't open, usually means the string was cut off.
Validate Base64 in your language.
PythonFull Python guide →
import base64, binascii
def is_valid_base64(s: str) -> bool:
try:
base64.b64decode(s, validate=True) # rejects characters outside the alphabet
return True
except binascii.Error: # bad characters or incorrect padding
return False
JavaScriptFull JavaScript guide →
const BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
const isValidBase64 = (s) => BASE64.test(s);
Linux / macOSFull Linux and macOS guide →
printf '%s' "$STR" | base64 -d > /dev/null 2>&1 && echo valid || echo invalid
PowerShellFull PowerShell guide →
try { [void][Convert]::FromBase64String($s); "valid" } catch { "invalid" }
Note that .NET's FromBase64String ignores whitespace and GNU base64 -d ignores line breaks, so for strict checks use the regular expression above.
About this tool.
In strict RFC 4648 §4 form, a valid Base64 string contains only A–Z, a–z, 0–9, +, and /, optionally followed by 1 or 2 = padding characters. Its total length must be divisible by 4. In permissive mode, the validator also accepts whitespace, URL-safe variants (- and _), and missing padding.
Common causes: it contains characters outside the alphabet (often a stray space, plus sign, or quote from copy-paste), its length is not a multiple of 4, padding is in the wrong place, or it is actually a different encoding (like hex or URL-encoded text). The validator shows a specific reason for each failure.
It estimates the size of the original data. Base64 expands data by about 33% — every 4 Base64 characters represent 3 bytes. A 100-character Base64 string decodes to about 75 bytes. The exact count helps verify you have the complete encoded data, not a truncated copy.
When you need to verify that a string conforms to RFC 4648 §4 exactly — useful for API request validation, format compliance checks, or debugging interoperability issues between systems that disagree about whether to accept URL-safe variants or missing padding.
+ and / for index values 62 and 63. Both are reserved in URLs — + can read as a space and / separates path segments. URL-safe Base64 (RFC 4648 §5) swaps + for - and / for _ so the string travels safely in query strings and filenames without extra percent-encoding. This validator accepts both variants.base64_decode($data, true), for example, returns false the moment it hits a character outside the Base64 alphabet. If a string picked up line breaks in transit — common with PEM blocks or email — strip whitespace with a regex before decoding, or choose non-strict mode deliberately.==; if it holds two bytes (16 bits) it appends a single =. The padding tells a decoder exactly how many bytes the last block really contained.==. Remainder 2 (two leftover bytes, 16 bits) encodes to three characters plus a single =. Since the maximum padding is two characters, === can never appear in a valid string.A–Z a–z 0–9 + / =. Common causes are stray whitespace or newlines from copy-paste, percent-encoded sequences such as %2B instead of +, or feeding a URL-safe string (containing - or _) to a standard decoder. Strip whitespace and confirm the variant before decoding.const clean = raw.replace(/[^A-Za-z0-9+/=]/g, '');
const decoded = atob(clean);This stops strict decoders from throwing on characters that slipped in during transport or copy-paste.