Three segments, one string
A JWT joins three parts with dots: header, payload, signature. The header declares the algorithm, typically HS256 with type JWT; the payload carries claims such as subject, role and issue time; the signature hashes the first two encoded parts. Each uses Base64URL — plus becomes minus, slash becomes underscore, padding dropped — because those characters are unsafe in URLs and headers. Decoding needs no key; verification does.
Steps
- Write claims in the payload editor, or use the helper to fill iat, exp and sub.
- Choose HS256, HS384 or HS512 and an expiry in seconds that becomes exp.
- Enter the secret and generate the token.
- Paste a token into the decode field with the same secret to see header, payload and verification.
- Load the example or clear.
Claims that matter
exp, iat and nbf are all Unix seconds, never milliseconds. sub identifies the subject, iss names the issuer and aud the intended audience to stop tokens being replayed elsewhere, while jti supports anti-replay when paired with a server-side deny list. Clock skew between issuer and verifier justifies a small tolerance, but a generous one hollows out expiry entirely.
Algorithms and key length
HS256 is HMAC-SHA256 with a shared secret held by both sides. Short secrets provide no security; the key should be at least as long as the hash output, thirty-two bytes. RS256 uses asymmetric keys — private to sign, public to verify — suiting multi-party verification at the cost of key management. Tokens with alg none carry no signature and can be forged by anyone, so servers must reject that value explicitly, a lesson written into several historical vulnerabilities.
Common problems
Putting secrets in the payload, which is merely Base64 and readable by anyone. Omitting exp, turning a token into a permanent credential. Shipping the secret to the front end, which grants signing rights to everyone. Algorithm confusion, where the server trusts the header's alg and an attacker swaps it for none or an asymmetric scheme verified with the public key. And confusing seconds with milliseconds, pushing expiry millennia out.
Scope of the pattern:JWTs suit stateless propagation of identity and permissions across services, especially as short-lived access tokens. They are poor as the only session store, since revocation requires a deny list. They should not carry bulk data, because size lands on every request header. Long-lived credentials belong to revocable sessions or refresh tokens. In single sign-on the JWT is a carrier, while real session state still lives server-side.