JWT in one sentence

A JSON Web Token (JWT) is a signed piece of JSON passed between two parties with the guarantee that "these claims are intact and were not altered". Its most common use is session handling: a user signs in, the server issues a JWT, the client sends it with every subsequent request, and the server knows who is talking without a database lookup. Service-to-service authorization, password reset links and one-time confirmation links use the same structure.

Three parts: header, payload, signature

A JWT is three Base64URL strings separated by dots: xxxxx.yyyyy.zzzzz.

  1. The header states the token type and the signing algorithm, for example {"alg":"HS256","typ":"JWT"}.
  2. The payload carries the actual data, known as claims: a user identifier, roles, an expiry time and so on.
  3. The signature is the first two parts signed with the declared algorithm and a secret key. Change a single character in the payload and the signature no longer matches.

The first two parts are encoded, not encrypted. That is the most important sentence in this article: anyone can read the contents of a JWT. The signature prevents tampering, not reading.

How to read a JWT

Paste a token into the JWT decoder and the header and payload open as formatted JSON, with timestamps converted to readable dates. To do it by hand, Base64URL-decode each part: replace - and _ with + and /, add any missing = padding, and decode. When debugging, these claims matter most:

  • sub: who the token is about, usually a user id.
  • iss: who issued it. Prevents confusion when you have more than one identity provider.
  • aud: who it was issued for. A token minted for one API should not be accepted by another.
  • exp, iat, nbf: expiry, issued-at and not-before. All are Unix timestamps in seconds.
  • jti: a unique token id, useful for blocklists or one-time use.

Reading and verifying are different things. An online decoder shows the payload, but only a server that holds the key can verify the signature. Never paste a production token into a site you do not trust; while it is valid, it can be used in your name.

Signing algorithms: HS256 or RS256?

HS256 uses a single shared secret: the signer and the verifier know the same key. It suits simple systems where one server verifies its own tokens. RS256 and ES256 use a public/private key pair: the private key signs, and anyone with the public key can verify. In architectures where several services verify the same token, this keeps the private key in one place. The rule of thumb: if more than one party verifies, choose an asymmetric algorithm.

The most common mistakes

  • Secrets in the payload. Passwords, card numbers, national id numbers and even email addresses sit in the payload in plain text. Tokens end up in logs, browser history and error reports. Put only identity and authorization data in the payload.
  • Tokens that never expire. A token without exp is valid forever, and there is no easy way to revoke it once leaked. Minutes for access tokens and days for refresh tokens is common practice.
  • Trusting the algorithm in the header. If the verification code says "verify with whatever the header declares", an attacker can set alg to none, or switch RS256 to HS256 and make your public key act as the shared secret. The server must pin the algorithms it accepts on its own side.
  • Weak secrets. With HS256, a short or guessable key (secret, the company name) can be cracked offline. Use at least 32 random bytes; the password generator can produce a long random string.
  • Skipping aud and iss checks. A valid signature does not mean the token was meant for this application.
  • Storing tokens in localStorage. Any script on the page can read it. In browser clients, an HttpOnly, Secure cookie is the safer option.

Validation checklist

  1. Is the signature verified with an algorithm and key pinned by the server?
  2. Is exp in the past or nbf in the future? Is a small clock-skew tolerance (a few seconds) allowed?
  3. Is iss the expected provider and aud this application?
  4. Does the payload contain anything that should not be there?
  5. Is there a defined refresh and revocation flow? What happens to old tokens when a user signs out or changes their password?

Conclusion

Used correctly, JWT is a simple, portable tool that frees the server from holding session state. Most misunderstandings come from one confusion: treating encoding as encryption. Accept that anyone can read the contents, design the payload accordingly, and pin the algorithm and lifetime on the server. To see what a token you are holding actually carries, try the JWT decoder.