What Base64url is
Base64url is a variant of Base64 defined in RFC 4648, section 5. It turns any bytes into text made of 64 safe characters, like Base64, but swaps the two characters that cause trouble in URLs and file names: + becomes - and / becomes _.
JWTs, JWS and JWE all use Base64url, and they leave out the = padding (RFC 7515, section 2). So do PKCE code challenges and many other OAuth values. Whenever you see a long string of letters, digits, dashes and underscores in an auth flow, it is probably Base64url.
How the encoding works
The input bytes are taken three at a time, 24 bits. Those bits are split into four groups of 6 bits, and each group picks one character from the alphabet. Three bytes always become four characters.
| Values | Base64 | Base64url |
|---|---|---|
| 0 to 25 | A to Z | A to Z |
| 26 to 51 | a to z | a to z |
| 52 to 61 | 0 to 9 | 0 to 9 |
| 62 | + | - |
| 63 | / | _ |
| Padding | = | Usually left out |
When the input length is not a multiple of three, the last group is short. Standard Base64 fills it with = signs; Base64url in JWTs drops them, and decoders work out the missing length.
text {"alg":"RS256"}
base64 eyJhbGciOiJSUzI1NiJ9
base64url eyJhbGciOiJSUzI1NiJ9What this tool does
- Encodes text as UTF-8, or raw bytes given as hex, into Base64url.
- Decodes Base64url back to text, and always to hex as well.
- Shows decoded JSON formatted, which is handy for JWT parts.
- Adds or leaves out the
=padding, as you choose. - Tells you when input uses
+and/, which means it is standard Base64, and decodes it anyway. - Names the bad character or impossible length when decoding fails.
Everything runs in your browser. Use the button to feed the result back as input and go the other way.
Step by step
- Choose Encode or Decode.
- For encoding, choose whether the input is text or hex bytes, then type or paste it.
- For decoding, paste the Base64url string; spaces and line breaks are ignored.
- Copy the result.
Reading JWT parts by hand
Each part of a JWT between the dots is Base64url. Paste the first part to read the header, or the second to read the claims; the tool formats the JSON. The third part is the signature: it decodes to bytes, not text, so the tool shows it as hex.
For everyday work the JWT decoder does all three at once. This tool is useful when you want to see one part alone, edit it, and encode it again to understand how a token is built.
JWTs come in two other forms you may meet. An unsecured JWT with alg: none has an empty third part, so it ends with a dot. A JWS with a detached payload has an empty second part, so two dots sit next to each other. Both still use Base64url for the parts that are present.
Where Base64url shows up in OAuth and Keycloak
- JWT access tokens and ID tokens: every part.
- PKCE: the
code_challengeis the Base64url SHA-256 hash of thecode_verifier, without padding (RFC 7636). - JWKs: key numbers such as
n,e,x,yandkare Base64url. - Thumbprints:
x5t,x5t#S256and RFC 7638 key thumbprints are Base64url.
Use cases
Debugging a PKCE mismatch
If an authorization server says the code verifier does not match, check that the challenge was made with Base64url, not Base64, and without padding. A +, / or = in the challenge is the giveaway. The PKCE generator makes a correct pair.
Building test tokens step by step
Encode a header and a payload here to see the signing input of a JWT form in front of you. Then sign it with the JWT encoder.
Inspecting key material
Decode a JWK’s n or x to hex to compare it with a key printed by OpenSSL.
Common errors
| Message | Cause |
|---|---|
| “…” is not a Base64url character | A quote, space inside the value, or other stray character from copying |
| The length is not possible | One character too many or too few, often a cut-off copy |
| Uses + and /, so it is standard Base64 | The value was encoded with plain Base64 |
| The bytes are not UTF-8 text | Binary data such as a signature or a key; read the hex |
Padding and length, worked out
Because Base64url in JWTs has no padding, a decoder must work out how many bytes the last group holds from the length alone. The rule is simple: take the length modulo 4.
| Length mod 4 | Last group holds | Padding a decoder adds |
|---|---|---|
| 0 | A full 3 bytes | None |
| 2 | 1 byte | == |
| 3 | 2 bytes | = |
| 1 | Impossible | The value is damaged |
A length that leaves 1 after dividing by 4 can never come from a correct encoder. It almost always means one character was lost or added when the value was copied. This tool reports it as an impossible length instead of guessing.
Base64url in code
Most languages have a Base64url function built in or in a standard library. Using it is safer than replacing characters by hand.
// JavaScript (browser and Node.js)
btoa(text).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
Buffer.from(bytes).toString('base64url'); // Node.js only
# Python
base64.urlsafe_b64encode(data).rstrip(b'=')
// Java
Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);Note that btoa in browsers accepts only characters up to U+00FF. Text with other characters must be turned into UTF-8 bytes first, which this tool does for you.
Checking a JWT part by hand
Decoding one part at a time is a good way to understand why a token fails to parse.
- Split the token at the dots and paste the first part. You should see JSON with
alg. - Paste the second part. You should see the claims as JSON.
- Paste the third part. You should see hex bytes; their count tells you the signature size, such as 256 bytes for RS256 with a 2048-bit key.
- If any part fails, the token was damaged where that part sits.
The same check helps with JWK members. A modulus n that decodes to 256 bytes belongs to a 2048-bit RSA key; an EC x that decodes to 32 bytes belongs to a P-256 key.
Notes and limits
Base64url is an encoding, not encryption or compression. Anyone can decode it, and the output is about a third larger than the input.
Some systems accept Base64url with padding, others reject it. JWTs must not have padding; PKCE challenges must not either. When unsure, leave it out.
This page reads only what you type or paste. Nothing is sent to us.
When you compare two Base64url strings, compare the decoded bytes rather than the text. Padding, or its absence, changes the text but not the bytes, and some encoders differ in how they handle the unused bits at the end. Decoding both here and comparing the hex settles the question.
Base64url output is also case-sensitive. abc and ABC decode to different bytes, so tools that lower-case identifiers, such as some URL routers or databases with case-insensitive collation, can corrupt Base64url values silently.
Best practices
- Use a library function made for Base64url rather than replacing characters by hand.
- Decide on padding once and be consistent between encoder and decoder.
- Encode text as UTF-8 before Base64url so non-English characters survive.