Skip to content
Back to blog
Field notes · jwt

How JWT Works: Header, Payload and Signature

Learn how JWTs work, how to decode them in the browser, and the common pitfalls developers hit when handling tokens client-side.

4 min readSimon Wong

JSON Web Tokens (JWTs) are everywhere in modern web authentication. They power session management, API authorization, OAuth flows, and identity propagation across microservices. But despite how often we use them, most developers can't immediately tell what's inside a given token without help. That's where a JWT decoder comes in.

This guide walks through how JWTs are constructed, how to decode them safely in your browser, and the mistakes you should avoid when handling tokens on the client side.

What is a JWT and Why It Matters

A JWT is a compact, URL-safe way to represent claims between two parties. You'll typically encounter one as a long string with two periods inside, like xxxxx.yyyyy.zzzzz. Each segment is base64url-encoded, which is why the token looks like gibberish at first glance even though it's actually structured data.

JWTs matter because they're often the primary credential a server uses to identify you. Reading what's inside a token tells you who issued it, who it's for, what permissions it grants, and when it expires. When debugging an auth bug, the first useful question is almost always: "what does this token actually say?"

How JWT Works (RFC 7519)

A JWT has three dot-separated parts, each base64url-encoded:

  1. Header - tells you the signing algorithm and token type. A typical header looks like { "alg": "HS256", "typ": "JWT" }.
  2. Payload - the claims, which is just a JSON object. Standard claims defined in RFC 7519 include iss (issuer), sub (subject), aud (audience), exp (expiration time), nbf (not before), iat (issued at), and jti (JWT ID). Applications can add custom claims like role, email, or anything else.
  3. Signature - a cryptographic signature over the header and payload, computed with the secret or private key.

Common signing algorithms include HS256 (HMAC with a shared secret), RS256 (RSA signature with a public/private key pair), and ES256 (ECDSA). The signature lets the server verify that the token wasn't tampered with - decoding the token does not verify it.

Step-by-Step: Decoding a Token

Decoding a JWT is straightforward because each segment is just base64url-encoded JSON:

  1. Split the token on . into three parts.
  2. Convert each segment from base64url to base64 (replace - with +, _ with /, and pad with = if needed).
  3. Base64-decode the bytes, then UTF-8 decode them to get back JSON.
  4. JSON.parse the result.

You can do this in the browser with atob and TextDecoder, or you can paste your token into our JWT Decoder and see header, payload, signature, algorithm, and expiry rendered instantly.

Common Pitfalls

Decoding is not verifying

Decoding a JWT is just base64 + JSON. Anyone can do it. The signature is what makes a JWT trustworthy, and verifying the signature requires the secret (for HMAC) or the public key (for RSA/ECDSA). A decoded token tells you what someone claims - it does not prove those claims are valid.

Never trust client-side claims

It's tempting to read a JWT in the browser and use the contents to decide what to render. Use this only for UX hints (e.g., "show the username"). Never use client-side claim values for security decisions. The browser cannot verify the signature without the server's secret, and even if it could, the user controls the storage where the token lives.

Watch out for None-algorithm attacks

Older or misconfigured libraries may accept tokens with "alg": "none", meaning they trust any unsigned token. Always validate that the algorithm matches what your server expects, and reject none outright. This is one of the oldest JWT vulnerabilities and still appears in real audits.

Don't paste production tokens into random websites

A JWT is bearer credentials - whoever holds it can usually use it. Pasting a production token into an online decoder that sends data to a server is the same as leaking it. Always use a decoder that runs entirely in the browser, like ours, where the token never crosses the network.

FAQ

Can I decode a JWT without the secret?

Yes. Decoding only requires base64 and JSON parsing. You only need the secret to verify the signature or to mint new tokens.

How do I check if a JWT is expired?

Look at the exp claim, which is a Unix timestamp in seconds. Compare it to the current time. If Date.now() / 1000 >= exp, the token is expired. Our decoder shows this status badge automatically.

Why does my decoded payload have weird characters?

JWTs are base64url-encoded, not base64. The two are similar but use different characters and padding. If you decode with plain base64, non-ASCII characters or padding may corrupt the result. Always handle the -/_ substitution and re-pad before decoding.


Try our JWT Decoder to inspect your tokens.