JWT Tokens Explained: Structure, Claims, and Debugging
Decode header, payload, and signature. Understand exp, HS256 vs RS256, and fix auth failures fast.
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
| Claim | Meaning |
|---|---|
| sub | Subject — usually user ID |
| exp | Expiration Unix timestamp |
| iat | Issued-at time |
| iss | Issuer URL or service name |
| aud | Intended 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
Decode without verifying
Confirm structure and read exp, aud, and custom claims.
- 2
Check expiration
Convert exp to human time; refresh tokens if expired.
- 3
Verify signature
Use the correct secret or public key and algorithm from the header.
- 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.
Related posts
Practical articles on writing, development, design, and productivity — each tied to a free XSular tool you can use right away.
What Makes a Strong Password in 2025?
A complete guide to password security, common mistakes, and how to protect your accounts.
Jan 22, 2025Unix Timestamps Explained for Non-Developers
What is a Unix timestamp, why it starts at 1970, and how to convert them easily.
Jan 28, 2025Binary Numbers Explained for Beginners
How computers think in 0s and 1s, and how to convert text to binary yourself.
Feb 3, 2025