Skip to main content

No token data leaves your browser except JWKS public key fetches you explicitly initiate.

View source

Introduction to JWT

A JSON Web Token (JWT) is a compact, URL-safe token format defined by RFC 7519. It encodes a set of claims — statements about a subject — as a JSON object that is digitally signed or integrity-protected using a Message Authentication Code (MAC).

JWTs are the backbone of modern, stateless authentication and authorisation patterns. They are used everywhere from OpenID Connect identity layers to API access control.

What a JWT looks like

A JWT is three dot-separated Base64url-encoded segments:

header.payload.signature

Here is a concrete example:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjk5OTk5OTk5OTksInJvbGUiOiJhZG1pbiJ9.7MgJvDCvbJwNu7-KVYwCQWF9qX8y3GzD3b-lNHAhTkI

Each segment serves a distinct purpose.

The three parts

The header is a JSON object that describes the cryptographic operations applied to the token. It always contains a signature or MAC algorithm (alg) and may include a token type (typ).

{
  "alg": "HS256",
  "typ": "JWT"
}

A complete reference of supported algorithms can be found in the Algorithms section.

Payload

The payload contains the claims — statements about the subject and metadata about the token itself. Claims fall into three categories:

  1. Registered claims — predefined claims defined in the JWT specification that provide interoperability.
  2. Public claims — claim names that are registered in the IANA JSON Web Token Claims registry or use a collision-resistant name (a URI or a namespaced value).
  3. Private claims — custom claims agreed upon between the issuer and consumer, used for application-specific data.

Standard registered claims

The JWT specification defines seven registered claim names:

ClaimFull namePurpose
issIssuerIdentifies who issued the JWT
subSubjectIdentifies the subject of the JWT
audAudienceIdentifies the intended recipient(s) of the JWT
expExpirationUNIX timestamp after which the token is invalid
nbfNot BeforeUNIX timestamp before which the token is not valid
iatIssued AtUNIX timestamp when the token was created
jtiJWT IDUnique identifier for the token (prevents replay)

A detailed explanation of each of these claims is available in the Claims reference.

Example payload

{
  "sub": "1234567890",
  "name": "John Doe",
  "iat": 1516239022,
  "exp": 9999999999,
  "role": "admin"
}

This payload states that the subject (sub) is user 1234567890, that the user’s display name is “John Doe”, that the token was issued at UNIX time 1516239022, and that it expires at UNIX time 9999999999. The role claim is a private claim added by the application.

Signature

The signature is the result of applying the algorithm named in the header to the following input:

HMACSHA256(
  base64urlEncode(header) + "." +
  base64urlEncode(payload),
  secret
)

For symmetric algorithms (HS256, HS384, HS512) the same secret is used to create and verify the signature. For asymmetric algorithms (RS256, ES256, etc.) the token is signed with the private key and verified with the corresponding public key. This distinction has important security implications — see the Verification and Security sections.

When and why JWTs are used

Stateless authentication

In a traditional session-based architecture, the server stores session state in memory or a database. The client holds only a session cookie; every request requires a server-side lookup to reconstruct the session.

JWTs invert this model. The token itself carries all the information the server needs: who the user is, what they are authorised to do, and when the token expires. The server can validate the token without consulting a database. This is the defining characteristic of stateless authentication.

The trade-off is that a stateless JWT cannot be revoked before its natural expiry. If a token is compromised, the issuer cannot invalidate it unless it maintains a blocklist — which reintroduces state. For this reason, JWTs are typically short-lived (minutes to hours) and paired with refresh tokens for longer sessions.

Claims-based identity

JWTs decouple identity from a particular authentication mechanism. An OpenID Connect identity provider can issue a JWT that asserts not only “this user logged in” but also claims about their email, profile picture, and group membership. Any service that trusts the issuer’s public key can read these claims without needing to call back to the identity provider.

This makes JWTs a natural fit for:

Access tokens vs ID tokens

JWTs appear in two closely related but distinct roles:

AspectAccess TokenID Token
PurposeAuthorisation — grants access to a resourceAuthentication — proves the user’s identity
StandardOAuth 2.0 (no mandated format)OpenID Connect (always a JWT)
Who reads itThe resource server (API)The client application
ContentsScopes, permissions, resource accessClaims about the end-user (name, email, etc.)

An ID token is always a JWT and always signed. An access token may be a JWT but can also be an opaque string — this depends on the authorisation server’s implementation.

Security considerations

Because JWTs are self-contained, they demand careful handling:

The Security and Verification pages cover these topics in depth, and the Decoder tool lets you inspect any JWT client‑side.

Further reading