·11 min read
What is JWT? JSON Web Token Explained with Structure, Claims, and Security
JWT (JSON Web Token) is a compact format for securely transmitting claims between systems. It is widely used for API authentication, session handling, and authorization in modern web apps.
Table of Contents
What is JWT?
JWT stands for JSON Web Token, defined by RFC 7519. It is a URL-safe token format used to represent claims as a signed JSON object.
A server can issue a JWT after login, and clients send it in an Authorization: Bearer <token> header on subsequent requests.
JWT Structure: Header, Payload, Signature
A JWT has three Base64URL-encoded parts separated by dots:
header.payload.signature- Header: token type and signing algorithm (for example, HS256).
- Payload: claims such as user ID, roles, and expiration.
- Signature: verifies integrity and authenticity.
JWT Claims Explained
Common registered claims include:
iss: issuersub: subject (usually user id)aud: audienceexp: expiration timestampiat: issued-at timestampnbf: not-before timestamp
Avoid placing secrets or sensitive personal data inside payload claims, because payload content can be decoded by anyone who has the token.
How JWT Authentication Works
- User signs in with credentials.
- Server validates user and issues an access token JWT.
- Client stores token (prefer secure HTTP-only cookie when possible).
- Client sends token with API requests.
- Server verifies signature and claims before serving protected data.
HS256 vs RS256
| Algorithm | Key Type | Typical Use |
|---|---|---|
| HS256 | Shared secret | Single-service or tightly controlled systems |
| RS256 | Public/private key pair | Distributed systems and third-party verification |
Security Best Practices
- Set short access-token lifetimes using
exp. - Use refresh tokens with rotation and revocation support.
- Always validate signature, issuer, audience, and expiration.
- Reject unsigned tokens and explicitly control allowed algorithms.
- Serve tokens only over HTTPS.
JWT Tools
Use these tools to inspect and create JWTs while testing your auth flows:
References
- Jones, M., Bradley, J., and Sakimura, N. (2015). RFC 7519: JSON Web Token (JWT). IETF. https://datatracker.ietf.org/doc/html/rfc7519
- Sheffer, Y., Hardt, D., and Jones, M. (2020). RFC 8725: JSON Web Token Best Current Practices. IETF. https://datatracker.ietf.org/doc/html/rfc8725
- OWASP Foundation. JSON Web Token Cheat Sheet for Java. https://cheatsheetseries.owasp.org/cheatsheets/JSON_Web_Token_for_Java_Cheat_Sheet.html