Base64URL Encode/Decode
Encode, decode and convert Base64URL with optional padding, strict JWT rules, hex view for binary data and file support
Everything is processed in your browser. Files up to 5 MB can be encoded with the button on the right.
What the tool found
Get the right Base64 variant for the system that will read it
"Base64URL" is not one format but a small family: the alphabet is fixed (- and
_ instead of + and /), but padding is optional and
every library has its own default. That is why a token that one tool produces is rejected by
another with errors like Incorrect padding or InvalidCharacterError. This tool
encodes, decodes and converts between the variants, tells you exactly what is wrong with
an input (the position of the first bad character, truncated data, wrong padding) and shows
the real bytes when the content is not text.
Three choices decide which string you need
Alphabet. Standard Base64 uses + and /; the URL-safe
alphabet of RFC 4648 section 5 uses - and _, so the result can sit in
a URL path or a file name without escaping. The two bytes FB FF show the
difference: +/8= in standard Base64 and -_8 in Base64URL without padding.
Padding. The = characters bring the length to a multiple of 4.
RFC 4648 allows leaving them out when the length is known, and the JWT/JWS specification
(RFC 7515) requires it: the value is Base64url "with all trailing = characters omitted" and
without line breaks or whitespace. Libraries disagree on the default: Python's
urlsafe_b64encode and Java's Base64.getUrlEncoder() add padding,
Node's 'base64url' encoding and Go's base64.RawURLEncoding do not.
Use the Add = padding option to produce the form your consumer expects.
Text or bytes. Text is first turned into UTF-8 bytes; binary data such as a
signature, a key or a file is encoded as it is. The size is about 4 characters for every 3
bytes, one third larger. Without padding, n bytes need ceil(4n/3) characters: 1 byte
gives 2, 2 bytes give 3, 3 bytes give 4.
Errors this page helps you diagnose
Python: binascii.Error: Incorrect padding.
base64.urlsafe_b64decode("-_8") fails because the length is not a multiple of 4,
while "-_8=" works. JWT segments never have padding, so restore it before decoding:
s + "=" * (-len(s) % 4).
Browser: InvalidCharacterError from atob.
atob only knows the standard alphabet, so atob("-_8") throws; replace
- with + and _ with / first (atob does
accept a missing padding). btoa has the opposite limit: it only takes characters up to
U+00FF, so btoa("é😀") throws too. Encode the text to UTF-8 bytes first.
"Invalid length". A valid unpadded string leaves 0, 2 or 3 characters at the end, never 1. A remainder of 1 means the value was truncated or has an extra character, and no decoder can recover it.
Two strings, same bytes. The unused trailing bits of the last character are
normally ignored, so YQ and YR both decode to a in Node,
and Python's b64decode does the same for YQ== and YR==. The tool flags non-canonical input. When you compare
tokens, compare the decoded bytes, not the text.
Garbled output. If the decoded bytes are not valid UTF-8, the content is binary. Auto mode then shows a hex dump instead of replacement characters, and you can download the raw bytes.
Convert, inspect and encode files
Convert swaps the alphabet and adds or removes padding without decoding, so
the bytes are guaranteed to be untouched. It is the quick fix for a value copied from
openssl base64 that has to go into a URL, or for a Base64URL value that a
standard decoder refuses.
Decode is lenient by default: it accepts padding, line breaks and the
standard alphabet and lists what it had to fix. Switch on Strict (JWT rules) to check
that a string really follows the JWT rules: only A-Z a-z 0-9 - _, no padding and no
whitespace. When the result is JSON, Auto mode pretty-prints it, which makes the header or
payload of a token readable straight away. For the full claims view, including dates, use the
JWT decoder.
Files up to 5 MB can be encoded without leaving the page, and the bytes
of a decode can be downloaded as a file. Inputs of any length are handled in chunks:
the common btoa(String.fromCharCode(...bytes)) pattern throws a
RangeError for inputs of around 200,000 bytes because of the argument limit.
Limits: Base64URL is an encoding, not encryption, and the payload of a JWT can be read by anyone who has the token. This page does not verify signatures, does not decode streaming data and shows text as UTF-8 only.
Code Examples
Node.js and the browser: one alphabet each
// Node 16+
Buffer.from([0xfb, 0xff]).toString("base64url"); // "-_8"
Buffer.from([0xfb, 0xff]).toString("base64"); // "+/8="
// Browser: atob only knows the standard alphabet
atob("-_8"); // InvalidCharacterError
atob("-_8".replace(/-/g, "+").replace(/_/g, "/")).length; // 2 (padding may be missing)
btoa("é😀"); // InvalidCharacterError: not Latin-1Python: restore the padding of a JWT segment
import base64
base64.urlsafe_b64encode(b"\xfb\xff") # b'-_8=' (Python pads by default)
base64.urlsafe_b64decode("-_8=") # b'\xfb\xff'
base64.urlsafe_b64decode("-_8") # binascii.Error: Incorrect padding
s = "-_8" # no padding, as in a JWT
base64.urlsafe_b64decode(s + "=" * (-len(s) % 4)) # b'\xfb\xff'Java: padding is on by default
byte[] b = {(byte) 0xfb, (byte) 0xff};
Base64.getUrlEncoder().encodeToString(b); // "-_8="
Base64.getUrlEncoder().withoutPadding().encodeToString(b); // "-_8"
Base64.getEncoder().encodeToString(b); // "+/8="
Base64.getUrlDecoder().decode("-_8"); // accepts the unpadded formThe JWT header, encoded
Buffer.from('{"alg":"HS256","typ":"JWT"}').toString("base64url");
// "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"Standards & Specifications
- RFC 4648 — The Base16, Base32, and Base64 Data Encodings (section 5) — Defines the URL and filename safe alphabet, the optional padding and the canonical encoding (section 3.5)
- RFC 7515 — JSON Web Signature, section 2 (Base64url Encoding) — Requires Base64url without padding and without whitespace for JWS and JWT segments
- RFC 7519 — JSON Web Token (JWT) — Defines the three-segment token format built on Base64url
Frequently Asked Questions
Why does Python say 'Incorrect padding' when I decode a JWT segment?
JWT and JWS segments omit the trailing = characters, but base64.urlsafe_b64decode requires the length to be a multiple of 4. Add the padding back before decoding: s + '=' * (-len(s) % 4). This tool does that for you in lenient mode and in strict mode shows what a JWT-style string must look like.
Why do atob and btoa fail with Base64URL and with emoji?
atob only knows the standard alphabet, so '-' and '_' raise InvalidCharacterError: replace them with '+' and '/' first. btoa only accepts characters up to U+00FF, so btoa('é😀') also throws. Encode the text to UTF-8 bytes first (TextEncoder), which is what this tool does.
Should I keep the = padding?
Follow the consumer. JWT and JWS require it to be omitted (RFC 7515). RFC 4648 section 5 allows either form. Python's urlsafe_b64encode and Java's Base64.getUrlEncoder() add padding by default, while Node's 'base64url' and Go's RawURLEncoding leave it out. A decoder that insists on one form rejects the other, so the Add = padding option exists.
What does 'length remainder 1' mean?
Every 4 Base64 characters carry 3 bytes, so a valid string without padding can leave 0, 2 or 3 characters at the end, never 1. A remainder of 1 means the string was cut off or has an extra character, usually from a copy and paste that dropped the end or added a stray character.
Two different strings decode to the same bytes. Is that a bug?
It is allowed by the format. The last character of an unpadded string can carry unused bits that decoders usually ignore, so 'YQ' and 'YR' both decode to 'a'. The tool warns about this non-canonical form. If you compare tokens or signatures, compare the decoded bytes, not the text.
Why does the decoded output look like garbage?
The data is not text. Keys, signatures, hashes, images and compressed data are raw bytes that are not valid UTF-8. In Auto mode the tool then shows hex; you can also download the bytes as a file.
How much bigger does Base64URL make my data?
About one third: every 3 bytes become 4 characters. 1,000,000 bytes become 1,333,334 characters without padding and 1,333,336 with padding. The Details panel shows both numbers for your input.
Is Base64URL encryption?
No. It is a reversible encoding with no key. The header and payload of a JWT are only Base64URL, so anyone who holds the token can read its claims. The signature protects against modification, not against reading.
Is my data sent to a server?
No. Encoding, decoding, conversion and file handling run in your browser; you can confirm it in the network tab of your developer tools.