Encode a JWT header
{"alg":"HS256","typ":"JWT"}eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
Every JWT starts with eyJ, because {" always encodes to those three characters.
Encode and decode URL-safe Base64, the variant used in JWTs, tokens and links. Choose padding or no padding, paste a JWT part to read it, and keep everything in your browser.
+ and /), with or without =.{"alg":"HS256","typ":"JWT"}eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
Every JWT starts with eyJ, because {" always encodes to those three characters.
eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ
{"sub":"1234567890","name":"John Doe","iat":1516239022}This is the middle part of a JWT (between the two dots). It has no padding, which is normal for Base64URL.
???
Pz8_
Standard Base64 gives Pz8/. The / would break a URL path, so Base64URL uses _ instead.
Hi
SGk
Standard Base64 is SGk=. Base64URL usually drops the = because the decoder can work out the length.
Base64URL is a version of Base64 that is safe to put in URLs, file names and HTTP headers. It uses the same 64-character idea as standard Base64, but replaces the two characters that cause trouble in URLs: + becomes - and / becomes _. It usually leaves out the = padding as well. It is defined in RFC 4648, section 5, as "Base 64 Encoding with URL and Filename Safe Alphabet".
Like standard Base64, it turns every 3 bytes into 4 characters, so the output is about 33% larger than the input. It is an encoding, not encryption.
Three characters of standard Base64 have special meanings in a URL:
| Character | Meaning in a URL | What goes wrong |
|---|---|---|
+ | A space in query strings (form encoding) | The server decodes it as a space and the data is corrupted. |
/ | Path separator | The value is split into extra path segments. |
= | Separates a key from its value | It has to be percent-encoded as %3D, which makes links longer and fragile. |
Base64URL avoids all three, so the value can go into a URL path, a query string, a cookie or a file name without any extra escaping.
| Base64 (standard) | Base64URL | |
|---|---|---|
| Characters 0–61 | A–Z a–z 0–9 | A–Z a–z 0–9 |
| Character 62 | + | - |
| Character 63 | / | _ |
| Padding | Required (=) | Usually omitted |
| Spec | RFC 4648 §4 | RFC 4648 §5 |
| Typical use | Email, data URLs, PEM keys | JWTs, tokens, URLs, file names |
Converting between the two is a simple character swap: replace + with - and / with _, then remove or add the padding.
The = signs at the end of standard Base64 only tell the decoder how many bytes the last group holds. That information can also be calculated from the length, so most Base64URL formats drop it:
==).=).JWTs (RFC 7515) require Base64URL without padding. Some other systems expect the padding to be kept, which is what the Add = padding option is for.
A JSON Web Token is three Base64URL strings joined by dots:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c└────────── header ──────────┘ └────────────────────────── payload ──────────────────────────┘ └────────── signature ──────────┘Decoding a JWT does not verify it. Anyone can read the payload, so never put secrets in it. To check the signature and expiry, use a JWT decoder and verifier.
code_challenge is the Base64URL SHA-256 hash of the verifier, without padding./.const encoded = Buffer.from('Hi', 'utf8').toString('base64url'); // "SGk"const text = Buffer.from(encoded, 'base64url').toString('utf8'); // "Hi"function toBase64Url(bytes) { return btoa(String.fromCharCode(...bytes)) .replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');} function fromBase64Url(str) { const b64 = str.replace(/-/g, '+').replace(/_/g, '/'); const padded = b64 + '='.repeat((4 - (b64.length % 4)) % 4); return Uint8Array.from(atob(padded), (c) => c.charCodeAt(0));}function base64url_encode(string $data): string{ return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');} function base64url_decode(string $data): string|false{ return base64_decode(strtr($data, '-_', '+/'), true);}import base64 encoded = base64.urlsafe_b64encode(b'Hi').rstrip(b'=').decode() # "SGk" def b64url_decode(s: str) -> bytes: return base64.urlsafe_b64decode(s + '=' * (-len(s) % 4))encoded := base64.RawURLEncoding.EncodeToString([]byte("Hi")) // "SGk"decoded, err := base64.RawURLEncoding.DecodeString(encoded)binascii.Error: Incorrect padding (Python)
Base64URL values usually have no =, but Python's decoder requires it. Add the padding back first: s + "=" * (-len(s) % 4), then call base64.urlsafe_b64decode.
atob() fails with InvalidCharacterError on a JWT
atob() only understands standard Base64, and the token contains - or _. Swap them for + and / and add the padding before calling atob(), or use the browser function shown above. This tool accepts both forms.
The signature part of a JWT decodes to random symbols
That is correct. The signature is raw binary (an HMAC or RSA/ECDSA signature), not text. Only the header and payload are JSON.
A token works in a header but breaks when put in a URL
It was encoded with standard Base64, and the +, / or = got changed in transit (often + turned into a space). Re-encode it as Base64URL.
"The input has N characters. That length is impossible"
A Base64URL value can never leave exactly 1 character in its last group of 4. A character was lost while copying, often at the start or end of the token.
Almost. Base64URL uses - and _ instead of + and /, and usually leaves out the = padding. Everything else, including the 33% size increase, is the same.
It depends on the format. RFC 4648 allows padding, but JWTs and most URL tokens leave it out because the length already tells the decoder how many bytes are in the last group. This tool decodes both.
Copy the part between two dots (the header or the payload) and paste it in Decode mode. You will see the JSON. The signature part is binary, and decoding does not verify the token.
Every JWT header is a JSON object starting with {", and those two bytes always encode to eyJ in Base64URL.
No. Base64URL only uses letters, digits, - and _, which are all safe in URLs, so it can be used as-is in paths, query strings and file names.
Decoding runs entirely in your browser and nothing is uploaded. Still, treat live tokens like passwords: avoid sharing them, and prefer tokens that have already expired when testing.
Free, private developer tools that run in your browser. No signup, nothing uploaded, no waiting.
Tip: press Ctrl D to bookmark dev247.