What Is a JWT? Structure, Claims and Security
· 5 min read
A JSON Web Token (JWT, often pronounced "jot") is a compact, signed piece of JSON that one system gives another to say who someone is and what they may do. When you sign in to a web app, the server often returns a JWT, and your browser sends it back with each request in a header like Authorization: Bearer eyJhbGci…. JWTs are defined by RFC 7519.
This guide takes a real token apart, explains every part, and covers the security mistakes that matter most.
Three parts, separated by dots
Here is a complete JWT. You can paste it into the JWT Decoder to follow along.
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImV4YW1wbGUta2V5LTEifQ.eyJzdWIiOiJ1c2VyXzhmMTRlNDVmIiwibmFtZSI6IkFkYSBMb3ZlbGFjZSIsImVtYWlsIjoiYWRhQGV4YW1wbGUuY29tIiwicm9sZXMiOlsiYWRtaW4iLCJlZGl0b3IiXSwiaXNzIjoiaHR0cHM6Ly9hdXRoLmV4YW1wbGUuY29tIiwiYXVkIjoiaGFuZHlraXQtZXhhbXBsZSIsImlhdCI6MTc2MDAwMDAwMCwiZXhwIjo0MTAyNDQ0ODAwfQ._qMySSMT2Hk4TW7a-4Jiu8tcRe8sjaki9wONVr4ChMQ
It is three strings joined by dots:
- The header, which says how the token is signed.
- The payload, which holds the claims: the actual information.
- The signature, which proves the first two parts haven't been changed.
The header and payload are JSON, encoded with Base64URL: a variant of Base64 that uses - and _ instead of + and / and leaves out the = padding, so the token is safe to put in URLs and headers. Base64URL is an encoding, not encryption. Anyone holding the token can read its contents.
Decoding the example
Decoding the first part gives the header:
{
"alg": "HS256",
"typ": "JWT",
"kid": "example-key-1"
}
alg is the signing algorithm, here HMAC with SHA-256. typ says this is a JWT, and kid (key ID) tells the receiver which key was used, which matters when keys are rotated.
Decoding the second part gives the payload:
{
"sub": "user_8f14e45f",
"name": "Ada Lovelace",
"email": "ada@example.com",
"roles": [
"admin",
"editor"
],
"iss": "https://auth.example.com",
"aud": "handykit-example",
"iat": 1760000000,
"exp": 4102444800
}
The third part is the signature: 32 bytes of binary data, Base64URL-encoded. It only makes sense together with the key.
Claims
The fields in the payload are called claims. A few have standard meanings, defined in the RFC:
iss(issuer): who created the token, herehttps://auth.example.com.sub(subject): who the token is about, usually a user ID.aud(audience): which service the token is for. A service should reject tokens meant for someone else.exp(expiration time): after this moment the token must be rejected.nbf(not before): before this moment the token must be rejected.iat(issued at): when the token was created.jti(JWT ID): a unique ID, which lets a server refuse a token it has already seen.
Everything else, like name, email and roles above, is defined by the application that issued the token.
The three time claims are Unix timestamps: whole seconds since 1 January 1970, UTC. In the example, iat is 1760000000, which is 9 October 2025 at 08:53:20 UTC, and exp is 4102444800, the very start of the year 2100. Real access tokens usually expire within minutes or hours. The Unix Timestamp Converter turns these numbers into dates in any time zone.
How the signature works
The issuer computes the signature over the first two parts exactly as they appear in the token:
HMACSHA256(header + "." + payload, secret)
The example token was signed with the secret handykit-example-secret. A server that knows the secret recomputes the signature and compares it with the third part. If anyone changes a single character of the header or payload, for example to add an admin role, the signatures no longer match and the token is rejected.
There are two families of algorithms:
- HMAC (
HS256,HS384,HS512) uses one shared secret for both signing and checking. It is simple, but every service that checks tokens can also create them. - Public-key algorithms (
RS256,PS256,ES256,EdDSA) sign with a private key and check with a public key. Services can verify tokens without being able to create them, which is why identity providers such as OAuth and OpenID Connect servers usually use them. The public keys are often published as a JSON Web Key Set (JWKS).
Decoding is not verifying
This is the most important point about JWTs. Decoding a token, in a tool like the JWT Decoder or with a few lines of code, only reverses the Base64URL encoding. It tells you what the token claims. It does not tell you whether those claims are true, because anyone can write a token with any payload.
Before trusting a token, a server must:
- Verify the signature with the right key.
- Accept only the algorithms it expects. Never accept
alg: none, which means the token is unsigned. - Check
expandnbfagainst the current time. - Check that
issandaudare what it expects.
Use a maintained library, such as jose for JavaScript or PyJWT for Python, and pass it the key and the list of algorithms you accept. Early JWT libraries had serious bugs from trusting the token's own alg header, including accepting unsigned tokens and confusing public keys with HMAC secrets.
Keep secrets out of the payload
Because the payload is only encoded, never put passwords, API keys or personal data that the user shouldn't see in a JWT. Treat everything in it as readable by the person holding the token. If the contents must be confidential, use an encrypted token (JWE), which has five parts instead of three.
JWTs and sessions
A JWT carries its own data, so a server can check it without a database lookup. That is useful when many services need to check the same sign-in. The trade-off is that a signed token stays valid until it expires: you can't simply delete it on the server, the way you would delete a session.
That is why access tokens are usually short-lived, a few minutes to an hour, and paired with a refresh token that the server can revoke. For a single web app with its own server, a traditional session cookie is often simpler and easier to revoke. Whichever you choose, store the token where scripts on the page can't read it, such as an HttpOnly cookie, if cross-site scripting is a concern.
Try it
Paste a token into the JWT Decoder to see its header, payload and claims, with times shown as dates and a clear note when it has expired. It runs in your browser, so the token is never sent anywhere, but treat live tokens like passwords all the same: prefer expired or test tokens.