JWT Structure and Claims
What You'll Learn
You'll learn exactly how a JSON Web Token is structured and how its three parts work together to securely carry user identity and permissions.
The Three-Part Anatomy of a JWT
A JWT (JSON Web Token) consists of three Base64-encoded sections separated by dots: header.payload.signature. Think of it like a tamper-evident envelope: the header describes what's inside, the payload contains the actual message, and the signature proves nobody altered it in transit.
Header
The header specifies the token type (always JWT) and the signing algorithm used:
{
"alg": "HS256",
"typ": "JWT"
}
Payload (Claims)
The payload contains claims—statements about the user and metadata. There are three types:
Registered claims (standardized):
iss(issuer): who created the tokensub(subject): user identifier (like user ID)exp(expiration): when the token expires (Unix timestamp)iat(issued at): when the token was created
Custom claims (your application data):
{
"sub": "user123",
"roles": ["admin", "editor"],
"exp": 1735689600,
"iat": 1735603200
}
You can add any data you need—user roles, permissions, tenant IDs—but keep it minimal since JWTs are sent with every request.
Signature
The signature cryptographically verifies the token hasn't been tampered with. It's created by encoding the header and payload, then signing them with a secret key:
HMACSHA256(
base64UrlEncode(header) + "." + base64UrlEncode(payload),
secret
)
Any change to the header or payload invalidates the signature, making forgery detectable.
Key Takeaway: A JWT's three parts—header, claims-bearing payload, and cryptographic signature—create a self-contained, verifiable token that carries user identity and permissions without requiring server-side session storage.