Spunk Autos

Websites and web tools

JWT decoders and how to optimize your tokens

A JSON Web Token (JWT) is a compact string that carries claims, such as who a user is and when their session ends. Decoders let you read one in seconds. This page explains what a decoder shows, the difference between decoding and verifying, and how to keep tokens lean for a customer portal or booking app.

Anatomy of a token

A signed JWT has three parts separated by dots: header, payload and signature. The header and payload are JSON encoded with Base64URL, which is Base64 with URL-safe characters and no padding. The signature is computed over the first two parts with a key.

PartExample contentEncoded length in this example
Header{"alg":"HS256","typ":"JWT"}, 27 bytes36 characters
Payloadsubject, role, iat, exp, 71 bytes95 characters
Signature32-byte HMAC-SHA256 value43 characters
Whole tokenThree parts plus two dots176 characters

Decoding is not verifying

Anyone can decode a JWT; the payload is encoded, not encrypted. A decoder that shows the claims tells you nothing about whether the token is genuine. Your server must verify the signature with the right key and check the claims before trusting it.

  1. Accept only the algorithms you expect; reject none and anything unexpected.
  2. Verify the signature with the correct secret or public key.
  3. Check exp (expiry) and nbf (not before), allowing a small clock skew.
  4. Check iss (issuer) and aud (audience) match your system.
  5. Only then read the user's identity and role.

Optimizing token size

Tokens usually travel on every request in a header or cookie, so size adds up. Base64URL turns every 3 bytes into 4 characters.

  • Keep only the claims the server needs to authorize a request: a subject id, a role, expiry.
  • Look up profile details, such as name and vehicles, from the database when needed.
  • Use short claim names that the standard already defines.
  • Choose an algorithm with shorter signatures only if your security needs allow it.

Other good habits

  • Keep access tokens short-lived, measured in minutes, and use refresh tokens for longer sessions.
  • Do not put secrets or personal data in the payload; anyone holding the token can read it.
  • Store tokens in cookies marked HttpOnly, Secure and SameSite where your design allows.
  • Plan how to revoke access, since a valid JWT works until it expires.