Security · 5 min read
What Is a JWT and How Does It Work?
JSON Web Tokens (JWTs) are everywhere in modern authentication, from single sign-on to API access. But because they look like a random blob of characters, they can feel mysterious. This guide breaks down exactly what a JWT is, how the pieces fit together, and where developers commonly go wrong.
By the end you will be able to read a token, understand what the server trusts about it, and know why you should never store a secret inside one.
Try it yourself with the related tool.
Decode a JWT →Advertisement
The three parts of a JWT
A JWT is a single string made of three Base64URL-encoded parts separated by dots: header.payload.signature. The header says which algorithm signed the token. The payload carries the claims — the actual data, such as the user ID and an expiry time. The signature is a cryptographic seal that proves the first two parts have not been tampered with.
Crucially, the header and payload are only encoded, not encrypted. Anyone holding the token can decode and read them. What they cannot do is change them without invalidating the signature.
How signing makes a token trustworthy
When a server issues a JWT, it signs the header and payload with a secret (for HS256) or a private key (for RS256). When the token comes back on a later request, the server recomputes the signature and compares. If they match, the server knows the token was issued by someone holding the secret and has not been altered.
This is why a leaked token is dangerous until it expires: possession of a validly signed token is treated as proof of identity. Short expiry times limit that risk.
Common claims and what they mean
Standard claims include sub (the subject, usually the user), exp (expiry, a Unix timestamp), iat (issued-at), iss (issuer), and aud (audience). A server typically rejects a token whose exp is in the past or whose aud does not match.
The mistakes to avoid
Never put passwords, card numbers, or other secrets in a payload — it is effectively public. Do not trust a decoded token without verifying its signature and expiry. And keep your signing secret long, random, and server-side only.
