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?▾
Is the JWT payload encrypted?▾
What is the difference between registered, public, and private claims?▾
How does JWT signing work?▾
Can I edit a JWT token?▾
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