JWT Decoder: A Complete Guide to JSON Web Tokens
JSON Web Tokens (JWTs) have become the de facto standard for stateless authentication and authorization in modern web applications. Defined in RFC 7519, a JWT is a compact, URL-safe token that encodes a set of claims as a JSON object. This guide covers everything developers need to know about JWT structure, decoding, security considerations, and common pitfalls.
Anatomy of a JWT
Every JWT consists of three parts separated by dots: the header, the payload, and the signature. The header is a JSON object specifying the signing algorithm (such as HS256, RS256, or ES256) and the token type (typically “JWT”). The payload contains claims — key-value pairs that carry information about the user, session, or authorization context. The signature is a cryptographic hash of the header and payload, created using the specified algorithm and a secret or private key. Each part is independently Base64URL-encoded, making the entire token safe to transmit in HTTP headers, URL parameters, and cookies.
Understanding JWT Claims
The JWT specification defines seven registered claims: iss (issuer) identifies who created the token, sub (subject) identifies the principal, aud (audience) specifies the intended recipients, exp(expiration time) sets the token’s deadline, nbf (not before) defines the earliest valid time, iat (issued at) records creation time, and jti (JWT ID) provides a unique identifier for the token. Beyond these, applications add custom claims like user roles, permissions, tenant IDs, and any domain-specific data needed by the receiving service.
How JWT Decoding Works
Decoding a JWT does not require a secret key — it is simply the reverse of Base64URL encoding. Split the token at the dots, decode each of the first two segments from Base64URL to bytes, then parse the resulting bytes as UTF-8 JSON. The third segment (signature) remains as raw bytes unless you need to verify integrity. This is exactly what this tool does: pure client-side Base64URL decoding and JSON parsing, with no external libraries or server calls. This distinction between decoding and verification is critical — decoding reveals the contents, while verification confirms the token has not been tampered with and was issued by a trusted party.
Token Expiration and Time Claims
Time-based claims use Unix timestamps (seconds since the Unix epoch, January 1, 1970 UTC). The exp claim is the most important — once the current time exceeds this value, the token should be rejected. The iat claim helps track when a token was issued, useful for implementing token rotation or detecting tokens older than a certain threshold. The nbf claim prevents a token from being used before a specific time, which is useful when issuing tokens for future use. This tool automatically converts these timestamps to human-readable dates in your local timezone and shows whether the token is currently expired or valid.
JWT Security Best Practices
While JWTs are widely used, they require careful implementation to avoid security vulnerabilities. Always validate the algorithm in the header on the server side — the infamous “alg: none” attack exploits servers that blindly trust the header’s algorithm claim. Use asymmetric algorithms (RS256, ES256) when the token issuer and verifier are different services, and symmetric algorithms (HS256) only when both sides share a secret. Set short expiration times (minutes, not days) for access tokens and use refresh tokens for longer sessions. Never store sensitive data in the payload without encryption — Base64URL encoding is not encryption, and anyone with the token can read its contents. Always transmit JWTs over HTTPS and store them securely (httpOnly cookies are preferred over localStorage for browser applications).
Common JWT Use Cases
The most common use case is OAuth 2.0 and OpenID Connect, where JWTs serve as access tokens and ID tokens. Single sign-on (SSO) systems use JWTs to propagate authentication across services without requiring each service to call back to the identity provider. API gateways use JWTs to authorize requests before they reach backend services, reducing latency and load. Microservice architectures rely on JWTs to pass user context between services without shared session state. Even webhooks and server-to-server communication use JWTs to authenticate the sender and ensure payload integrity.
When Not to Use JWTs
JWTs are not always the right choice. For simple server-rendered applications with a single backend, traditional server-side sessions (stored in Redis or a database) are often simpler and easier to invalidate. JWTs cannot be revoked before expiration without maintaining a server-side blacklist, which partially defeats their stateless advantage. If your payload is large, JWTs add overhead to every request since the entire token is sent with each API call. For applications that need immediate revocation (e.g., account suspension), consider opaque tokens backed by a token store instead of, or in addition to, JWTs.