A JWT looks like three random strings joined by dots. It is not random at all: the first two parts are Base64URL-encoded JSON that anyone can read in a browser, and the third part is a signature that only the issuer can produce.
That asymmetry is the source of most JWT mistakes. Reading a token is trivial; trusting it without verification is a security bug.
The three parts
A JWT has the shape header.payload.signature:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkFkYSIsImV4cCI6MTc2MzUxMDQwMH0.5rGZ0m8k...
- Header — the signing algorithm (
alg) and token type (typ). - Payload — the claims: who the user is, when the token expires, who issued it.
- Signature — proof that the header and payload were produced by someone holding the key.
Decoding the first two parts gives you readable JSON:
{
"alg": "HS256",
"typ": "JWT"
}
{
"sub": "1234567890",
"name": "Ada",
"exp": 1763510400
}
There is nothing encrypted here. The signature protects the token against modification, not against reading.
Base64URL, not Base64
JWT uses Base64URL, a variant of Base64 that replaces + with - and / with _, and usually drops the = padding. That makes the token safe to put in a URL, a header or a cookie without percent-encoding.
When you decode a segment by hand, remember to reverse those substitutions first. A token segment that contains - or _ will fail in a standard Base64 decoder that does not expect them.
Decoding is not verification
Anyone can decode a JWT. Verification is a different operation with three requirements:
- Recompute the signature using the algorithm named in the header and the issuer’s key.
- Compare it in constant time with the signature in the token.
- Check the claims — especially
exp,nbf,audandiss.
A decoded payload tells you what the token claims. Only a verified payload tells you what the issuer actually granted. Forgetting this turns your application into a system where anyone can mint an admin token by editing the payload and leaving the old signature in place.
A decoder in a browser is a debugging tool. It is fine to inspect a token there; it is not fine to use the result as an authorization decision.
Claims worth checking
| Claim | Meaning | Why it matters |
|---|---|---|
exp | Expiry time, in seconds since the epoch | Reject expired tokens, with a small clock skew allowance |
nbf | Not valid before | Reject tokens used too early |
iat | Issued at | Useful for debugging and for maximum token age |
iss | Issuer | Ensure the token came from the expected authority |
aud | Audience | Ensure the token was meant for your service |
sub | Subject | The stable user or client identifier |
scope / scp | Granted permissions | Authorize the request, not just authenticate it |
Two claims deserve extra attention in reviews:
audis often omitted, which lets a token issued for one service be replayed against another.expis sometimes checked with>instead of<, or not checked at all, which produces tokens that never expire.
Algorithm confusion
The alg field is attacker-controlled until the signature is verified. A server that trusts alg from the token can be tricked:
alg: "none"— some libraries historically accepted unsigned tokens.alg: "HS256"when the server expectsRS256— a public key can be used as an HMAC secret in a confused verifier.
The rule is simple: the server chooses the allowed algorithms, not the token. Configure an explicit allowlist and reject everything else before touching the signature.
What should never be in the payload
The payload is readable by anyone who holds the token, including the user’s browser and any proxy or log that captures it.
Do not put in a JWT:
- passwords or password hashes;
- API keys, secrets or database credentials;
- full personal data that the client does not already know;
- large objects — tokens travel in headers, and headers have size limits.
Keep claims small and stable. If a client needs more profile data, fetch it from an API after authentication instead of packing it into the token.
Debugging a token
When a token fails, check in this order:
- Decode the header and payload and confirm the claims look right.
- Compare
expwith the current time — remember it is in seconds, not milliseconds. - Confirm
audandissmatch what the service expects. - Check which algorithm the verifier is configured to accept.
- Confirm the key or secret is the same one used to sign, including line breaks and trailing spaces.
- Look for whitespace or line wrapping introduced by a proxy or a copy-paste.
The JWT Decoder splits a token into header, payload and signature, converts timestamps into readable dates, and runs entirely in your browser. If you need to inspect a single segment, the Base64 tool decodes Base64URL as well. To compare two keys or fingerprints, the Hash Generator gives you a stable digest.
A practical checklist
- Verify the signature before reading any claim.
- Allowlist accepted algorithms on the server.
- Check
exp,nbf,audandisson every request. - Keep payloads small and free of secrets.
- Use short lifetimes and refresh tokens instead of long-lived access tokens.
- Treat browser decoders as debugging aids, never as authorization.
A JWT is a signed envelope, not a locked box. Once you treat the payload as public and the signature as the only proof, the design becomes much easier to reason about.