A JSON Web Token is the bouncer's stamp of the modern web: a compact string that says who you are and what you are allowed to do. You meet them in every OAuth 2.0 flow, most session-heavy APIs and almost all single sign-on setups. Reading one is a two-minute task once you know that the three dot-separated segments are base64url-encoded JSON — and decoding one is not the same as trusting it. Here is how to read a JWT safely, claim by claim.
Three parts, three dots
Every JWT has three base64url-encoded segments joined by dots. The header and payload are plain JSON; the signature is a hash of the first two segments computed with a secret key or a private key. A typical token looks like this:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiZXhwIjoxNzIwMDAwMDAwfQ.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U
The first segment decodes to a header, the second to a payload of claims, and the third is the cryptographic proof that neither of the first two was tampered with.
The header: metadata that decides security
The header is the token's metadata. The two fields almost every JWT carries are alg (the signing algorithm) and typ (usually the literal JWT). The algorithm matters more than it looks:
| alg value | Meaning | Secret type |
|---|---|---|
| HS256 / HS384 / HS512 | HMAC with SHA | Shared symmetric secret |
| RS256 | RSA signature | Private / public key pair |
| ES256 | ECDSA signature | Elliptic-curve key pair |
| none | No signature at all | Nothing — reject immediately |
If a token arrives with alg set to none or missing a signature, that is an attack artifact, not a convenience. Treat it as invalid on sight.
The payload: standard claims
The payload is a JSON object of claims. The ones registered by the specification appear in almost every token:
- sub — subject, usually the user ID the token belongs to.
- iss — issuer, the service that minted the token.
- aud — audience, the service(s) the token was minted for.
- exp — expiry as Unix seconds; a token is dead after this.
- nbf — not before; do not accept the token before this time.
- iat — issued at, when the token was created.
- jti — a unique ID so the token can be revoked or traced.
Everything else is custom state scoped to your application — roles, tenant IDs, feature flags — readable by anyone who decodes the token.
Why decoding is not validating
A decoder does three things you must still do yourself. It does not verify the signature, it does not check exp, and it does not check aud or iss. The most famous JWT attacks exploit exactly that gap: an attacker takes a legitimately signed token, edits the payload, strips the signature and switches alg to none; or flips RS256 to HS256 so the server verifies the signature using the RSA public key as an HMAC secret. Always verify the signature and the exp claim before trusting a single word of the payload.
Reading a token step by step
To read a segment by hand, restore the padding base64url removes (the = characters), then decode. base64url is ordinary base64 with + replaced by - and / replaced by _ so the output survives URLs:
function base64UrlDecode(input) {
const padded = input + "=".repeat((4 - (input.length % 4)) % 4);
return atob(padded.replace(/-/g, "+").replace(/_/g, "/"));
}
Decoding the first segment above with padding restored yields {"alg":"HS256","typ":"JWT"} and the second yields {"sub":"1234567890","exp":1720000000}.
Decode fast, inspect safely
Paste a token into the JWT Decoder and it splits header, payload and signature, then pretty-prints the JSON so the claims are readable at a glance. When the payload nests deeply, push it through the JSON Formatter for a tree view, or use the Base64 Encoder/Decoder to inspect each segment independently and confirm exactly how the bytes map back.
Frequently asked questions
Is it safe to paste a JWT into an online decoder? For test and development tokens, yes. For real production tokens with long-lived secrets, treat them like passwords — decode locally, or use a decoder that never transmits the token over the network.
Why does the base64 output never contain + or /? Those characters are not URL-safe, and JWTs travel inside URLs, headers and cookies. base64url substitutes - and _, which are safe everywhere, and drops the = padding.
Can I store sensitive data in a JWT's payload? Only if the token is short-lived and you accept full disclosure. The payload is encoded, not encrypted — anyone who captures the token can read it. Use JWE (encrypted tokens) or reference IDs for anything sensitive.