JWT Structure Explained: Header, Payload & Signature

Published on · 647 words

Want to follow along with this guide? Open the free JWT Debugger and test every pattern in real time with match highlighting and explanations.

JSON Web Tokens (JWT) are the standard for representing claims securely between two parties. They are used extensively in authentication, authorization, and information exchange. Understanding the internal structure of a JWT is essential for every developer working with modern APIs and web applications.

A JWT is a compact, URL-safe token composed of three Base64URL-encoded parts separated by dots: Header.Payload.Signature. Each part serves a specific purpose, and together they form a self-contained token that can be verified and trusted without server-side session storage.

The JWT Header

The header consists of two pieces: the type of token (JWT) and the signing algorithm being used, such as HMAC SHA256 or RSA. The header is Base64URL-encoded to form the first part of the JWT.

A typical header looks like: {"alg": "HS256", "typ": "JWT"}. The alg field specifies the cryptographic algorithm used to sign the token, while typ indicates the token type. Some headers may include additional fields like kid (Key ID) for key rotation scenarios.

The JWT Payload

The payload contains the claims — statements about an entity (typically the user) and additional metadata. There are three types of claims: registered, public, and private.

Registered claims are predefined fields like iss (issuer), exp (expiration time), sub (subject), and aud (audience). These provide standard metadata that JWT libraries understand. Public claims can be defined at will but should be registered with IANA to avoid collisions. Private claims are custom claims created to share information between parties that agree on using them.

It is important to note that the payload is Base64URL-encoded but NOT encrypted. Anyone who intercepts the token can read the payload. Never put sensitive information like passwords or secrets in a JWT payload.

The JWT Signature

The signature is created by taking the encoded header, the encoded payload, a secret, and the algorithm specified in the header. For example, if using HMAC SHA256: HMACSHA256(base64UrlEncode(header) + '.' + base64UrlEncode(payload), secret).

The signature serves two purposes: it verifies that the message was not changed along the way (integrity), and in the case of tokens signed with a private key, it can also verify that the sender of the JWT is who it says it is (authentication).

When you decode a JWT, you can verify the signature by recomputing it with the same secret and comparing it to the signature in the token. If they match, the token has not been tampered with.

Frequently Asked Questions

What are the three parts of a JWT?
A JWT consists of three parts separated by dots: the Header (contains token type and signing algorithm), the Payload (contains claims about the user and metadata), and the Signature (verifies the token was not tampered with and authenticates the sender).
Is the JWT payload encrypted?
No. The JWT payload is Base64URL-encoded but not encrypted. Anyone who has the token can decode and read the payload. Never store sensitive information like passwords or secrets in a JWT payload. Use JWE (JSON Web Encryption) if you need encrypted tokens.
What is the difference between registered, public, and private claims?
Registered claims are predefined standard fields like iss, exp, sub, and aud. Public claims should be registered with IANA to avoid naming collisions. Private claims are custom fields agreed upon between the parties exchanging the token.
How does JWT signing work?
The signature is computed by applying the specified algorithm (e.g., HMAC SHA256) to the encoded header, a dot, the encoded payload, and a secret key. The resulting signature is appended to the token. Verification recomputes the signature and compares it to the one in the token.
Can I edit a JWT token?
You can decode and read a JWT freely. You can also modify the header or payload and re-encode them, but the signature will no longer match unless you have the secret key. This is how JWT integrity protection works — any tampering invalidates the signature.

Try it now — free, private, and instant

Paste a JWT token to decode and inspect its header, payload, and signature instantly.

Launch the JWT Debugger