A JSON Web Token looks like three blocks of noise separated by dots. Two of them are base64-encoded JSON that anyone can read in a second. The third is a signature, and it is the only part doing any security work.

That is the whole design, and it is also the source of most JWT mistakes: people treat the token as if it were encrypted.

The three parts

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 . eyJzdWIiOiIxMjM0In0 . dBjftJeZ4CVPmB92K27uhbUJU1p1r_wW1gFWFOEjXk
        header                                  payload                        signature
Part What it is Encoded or encrypted
Header {"alg":"HS256","typ":"JWT"} Base64url — readable
Payload The claims, e.g. {"sub":"1234","name":"Ada"} Base64url — readable
Signature HMAC of header + payload with a secret Not readable, and not reversible

Paste any JWT into the JWT decoder and you will see the header and payload as plain JSON. That is not a bug or a security hole: base64 is a transport encoding, not a lock. Anyone who intercepts the token can read it.

So what does the signature do?

It proves the token was issued by someone holding the secret. Change one character of the payload — say, the user id — and the signature no longer matches, so the server rejects it. That is integrity, not confidentiality.

The distinction matters because it decides what you may put in a token. User id, roles, expiry: fine. A password, an API key, a national ID number: never. The payload is visible to the browser, to any logging system that records headers, and to anyone who finds the token in a URL.

The claims worth knowing

Claim Meaning
iss Issuer: who created the token
sub Subject: usually the user id
aud Audience: which service it is for
exp Expiry, as a Unix timestamp
nbf Not valid before, same format
iat Issued at, same format

exp is the one people get wrong. It is seconds since 1970, not milliseconds and not a date string, so a token with exp: 1735689600 expires on 1 January 2025. The Unix timestamp converter turns that number into a readable date if you are staring at a 401.

The mistakes that break it

alg: none. The spec allows an unsigned token. If a server accepts whatever algorithm the header claims, an attacker can set it to none and skip the signature entirely. Reject none explicitly.

Algorithm confusion. A server expecting RS256 (public key) can be tricked into verifying with HS256 (shared secret) using the public key as the secret. Pin the algorithm.

Decoding is not verifying. A decoder shows you the claims; it cannot tell you whether the token is valid, because validity requires the secret. Any tool that claims otherwise is guessing.

Long-lived tokens. A token that expires in 30 days is a password that cannot be changed. Short expiry plus a refresh token is the usual answer.

The base64 encoder is useful for inspecting the individual segments, and hash generator shows what the signature step looks like on its own.

A JWT is a signed postcard. Everyone on the route can read it; the signature only proves who sent it.

Hero photo: Code Coding, CC0, via Openverse (StockSnap).