7 min read

JWT Explained for Beginners

Understand what a JSON Web Token is, what its header, payload, and signature contain, and the security mistakes to avoid.

What a JWT is

A JSON Web Token (RFC 7519) is a compact way to pass a set of claims, such as a user ID and an expiry time, between two parties. The server signs the token so it can later detect if anyone changed it.

The three parts

A JWT is three Base64URL strings joined by dots: header.payload.signature. The header states the algorithm, the payload holds the claims, and the signature is computed over the first two parts with a secret or private key.

Header:  {"alg":"HS256","typ":"JWT"}
Payload: {"sub":"123","name":"Ada","exp":1767225600}
Token:   eyJhbGciOi...<header>.eyJzdWIiOi...<payload>.<signature>

Registered claims you will see

sub identifies the subject (usually the user), iat is when the token was issued, exp is when it expires, iss is who issued it, and aud is who it is intended for. exp and iat are Unix timestamps in seconds.

Common mistakes

Treating a JWT as encrypted: anyone can decode the payload, so never store secrets in it.

Trusting a token without verifying the signature, or accepting the alg value from the token without restricting it on the server.

Issuing long-lived tokens with no way to revoke them. Short expiry plus refresh tokens is the usual pattern.

Try the JWT Decoder