JSONHack
Validator · Formatter · Base64
Security Guide

What is JWT? JSON Web Token Explained

A JSON Web Token (JWT) is a compact, URL-safe token format used to securely transmit information between parties as a JSON object. JWTs are the backbone of modern authentication systems — used in REST APIs, OAuth 2.0, OpenID Connect, and single sign-on (SSO) implementations worldwide.

The Three Parts of a JWT

A JWT consists of three Base64URL-encoded parts separated by dots: header.payload.signature

Header

Specifies the token type (JWT) and the signing algorithm used, such as HS256 (HMAC-SHA256) or RS256 (RSA-SHA256).

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

Payload

Contains the claims — statements about the user and additional metadata. Claims include standard fields like sub, exp, iat, and custom fields.

{"sub": "user123", "name": "Alice", "exp": 1700000000}

Signature

Created by signing the encoded header and payload with a secret key or private key. Used to verify the token hasn't been tampered with.

Full JWT Example

The three parts are Base64URL encoded and joined with dots to form the final token string that is sent in API requests.

How JWT Authentication Works

  1. User logs in — sends username and password to the authentication server
  2. Server verifies credentials — checks the database and validates the password
  3. Server issues JWT — creates a signed token containing the user's ID, roles, and expiry time
  4. Client stores JWT — typically in memory, localStorage, or an HttpOnly cookie
  5. Client sends JWT — includes the token in the Authorization: Bearer <token> header on every API request
  6. Server validates JWT — verifies the signature and checks expiry before processing the request

Standard JWT Claims

sub — Subject

The user or entity the token represents. Usually a user ID or account identifier.

exp — Expiration

Unix timestamp after which the token is no longer valid. Always set this to limit token lifetime.

iat — Issued At

Unix timestamp of when the token was created. Used to calculate token age.

iss — Issuer

Identifies who issued the token — typically your auth server URL or application name.

aud — Audience

Identifies the intended recipients of the token — your API or application identifier.

nbf — Not Before

Unix timestamp before which the token must not be accepted. Useful for delayed activation.

JWT vs Session Tokens

JWT (Stateless)

  • No server-side storage needed
  • Works across multiple servers (microservices)
  • Self-contained — all info in the token
  • Cannot be invalidated before expiry without a blocklist

Session Tokens (Stateful)

  • Stored in server-side session store
  • Can be invalidated instantly
  • Requires sticky sessions or shared storage
  • Better for applications requiring immediate logout

JWT Security Best Practices

Common JWT Signing Algorithms

Decode a JWT right now

Paste any JWT to inspect its header, payload, claims, and expiry instantly.

Open JWT Decoder →