Development

JWT Tokens Explained: Structure, Claims, and Debugging

Decode header, payload, and signature. Understand exp, HS256 vs RS256, and fix auth failures fast.

Mar 5, 2025·10 min read

JSON Web Tokens (JWTs) carry signed claims between services—think session IDs, user roles, and API permissions packed into a compact string. They appear in OAuth flows, microservice auth, and mobile app backends. Understanding header, payload, and signature structure is essential before you debug a 401 or build your first protected API.

The three parts of a JWT

A JWT looks like `eyJhbGci...` with two dots separating three Base64URL-encoded segments: header (algorithm and type), payload (claims), and signature (proof the token was not tampered with). Decoding the first two segments is trivial—anyone can read them. Security comes from the signature verified with a secret or public key.

  • Header: `{ "alg": "HS256", "typ": "JWT" }`
  • Payload: claims like `sub`, `exp`, `iat`, and custom fields
  • Signature: HMAC or RSA over `header.payload`

Claims developers inspect daily

Standard registered claims
ClaimMeaning
subSubject — usually user ID
expExpiration Unix timestamp
iatIssued-at time
issIssuer URL or service name
audIntended audience

Expired tokens (`exp` in the past) should be rejected before your handler runs. Clock skew between servers causes edge-case failures—allow a small leeway (e.g. 30 seconds) in verification libraries.

HS256 vs RS256: which algorithm?

HMAC algorithms (HS256, HS384, HS512) use a shared secret—simple for monoliths and internal services. RSA/ECDSA (RS256, ES256) use a private key to sign and a public key to verify—better when many services verify but only one issues tokens.

Debugging authentication failures

  1. 1

    Decode without verifying

    Confirm structure and read exp, aud, and custom claims.

  2. 2

    Check expiration

    Convert exp to human time; refresh tokens if expired.

  3. 3

    Verify signature

    Use the correct secret or public key and algorithm from the header.

  4. 4

    Validate audience and issuer

    Mismatch here causes valid-looking tokens to fail policy checks.

Inspect JWTs in your browser

The JWT Tool on XSular Tools decodes header and payload, highlights expiration, verifies HMAC signatures, and generates test tokens—all client-side. Your secrets never leave the tab, which matters when debugging staging environments from a laptop.

Try it now

JWT Decoder & Generator — Free Online Token Tool

Decode, inspect, and verify JSON Web Tokens with header and payload views. Generate signed JWTs with custom claims, expiration, and HS256/HS384/HS512 algorithms. 100% client-side — free, secure, nothing uploaded.

Open JWT Decoder & Generator — Free Online Token Tool

Related posts

Practical articles on writing, development, design, and productivity — each tied to a free XSular tool you can use right away.

Read article