When debugging APIs you keep meeting long strings that begin with eyJ. Those are JWTs. Many people are surprised the first time they paste one into a decoder: the user info and expiry time are all in plain sight. That is because the first two parts of a JWT are encoded, not encrypted. This article uses one complete example token to show how to take it apart, judge whether it has expired, verify the signature, and which security misconceptions to avoid.
JWT structure: three parts separated by dots
A JWT (JSON Web Token, RFC 7519) is three Base64URL texts joined as header.payload.signature. Below is the token used throughout this article (for demonstration only; the secret is demo-secret):
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzg0MjEiLCJuYW1lIjoiQWRhIExvdmVsYWNlIiwicm9sZSI6ImVkaXRvciIsImlhdCI6MTc2MDQwMDAwMCwiZXhwIjoxNzYwNDAzNjAwfQ.32Ly9jxuicwBIgniALk2geoD2re8juuisCtiVCsT834| Part | Content | Decoded example |
|---|---|---|
| Header | Signing algorithm alg and token type typ | {"alg":"HS256","typ":"JWT"} |
| Payload | Claims: user identifier, role, times | {"sub":"user_8421","name":"Ada Lovelace","role":"editor","iat":1760400000,"exp":1760403600} |
| Signature | Signature computed over the first two parts with a secret | Binary data, 43 characters once Base64URL-encoded |
Base64URL: why the first two parts can simply be read
Base64URL is the URL-safe variant of Base64: it replaces + with -, / with _, and drops the trailing = padding. Its purpose is to let a token travel in a URL, cookie or HTTP header without extra escaping. It provides no secrecy whatsoever.
Original : {"a":">>>???"}
Base64 : eyJhIjoiPj4+Pz8/In0=
Base64URL : eyJhIjoiPj4-Pz8_In0To decode, reverse it: turn - back into +, _ back into /, pad with = to a multiple of 4 characters, Base64-decode and interpret as UTF-8. A payload with non-ASCII text such as {"name":"张三"} encodes to eyJuYW1lIjoi5byg5LiJIn0 and must be decoded as UTF-8 to avoid garbled output, which the JWT Parser handles. You can also do a manual Base64 decode in the Info Encoder / Decoder page to verify it yourself.
Decoding the example token step by step
- Split on . and you must get exactly three parts, otherwise it is not a valid JWS-format JWT. The parser page reports that three parts are expected when the count is wrong.
- Decode the first part to get {"alg":"HS256","typ":"JWT"}, which means HMAC-SHA256 signing.
- Decode the second part to get the payload. Note that iat and exp are Unix timestamps in seconds, not milliseconds.
- iat is 1760400000, which is 2025-10-14 00:00:00 UTC, and exp is 1760403600, which is 2025-10-14 01:00:00 UTC, so the lifetime is exactly 1 hour (3600 seconds).
- The page compares the current time with exp and marks the token as expired or valid. Since this example token expired long ago, you will see the expired badge, which makes it a good sample to practice reading.
Quick reference for common claims
| Claim | Meaning | Note |
|---|---|---|
| iss | Issuer | The server should check it is the expected issuer |
| sub | Subject, usually a user ID | Do not put email or phone numbers here |
| aud | Audience, who the token is for | Stops a token for service A being used against service B |
| exp | Expiration time (seconds timestamp) | The server must check it; client-side checks are only for UX |
| nbf | Not before | The token is invalid before this time |
| iat | Issued at | Useful for judging token age |
| jti | Unique token ID | For revocation or replay defence; a UUID works |
Verifying the signature: how HS256 is computed
An HS256 signature is HMAC-SHA256(secret, header.payload), where header.payload is the exact two Base64URL texts including the dot between them. The resulting bytes are Base64URL-encoded to form the third part. To verify, recompute with the same secret and compare with the third part of the token.
In the verification area of the JWT Parser, enter the secret and click Verify. The page uses the browser Web Crypto API and shows signature valid or invalid. With demo-secret the example token is valid. Change the secret to anything else, or change role from editor to admin and verify with the original signature, and the result is invalid. That is the whole point of a signature: any tampering with the first two parts breaks the match.
The limits, stated plainly: the page only verifies HS256, a symmetric algorithm, and not RS256, ES256 or other public-key algorithms. It checks whether the signature matches the secret, and does not replace the server's checks of exp, iss and aud. Decoding by itself verifies nothing.
What must not go in the Payload
Because anyone can decode the payload, never put in passwords, API keys, national ID numbers, card numbers or full phone numbers. Include only the minimum identifying information, such as user ID, role, tenant ID and times. If something truly must be transported confidentially, use JWE (JSON Web Encryption), or keep sensitive data on the server and let the token carry an opaque reference.
Common JWT security pitfalls
| Problem | Explanation | Defence |
|---|---|---|
| alg set to none | An attacker changes the header alg to none and strips the signature; a server that accepts it lets the token through | Fix an allowlist of algorithms on the server and reject none |
| Algorithm confusion | The server uses an RS256 public key as the HS256 secret, letting an attacker forge signatures with the public key | Enforce the algorithm by key type and never trust the alg in the token |
| Decode without verifying | The frontend trusts the payload, for example to show an admin menu | Make every authorization decision on the server after verifying the signature |
| Tokens leaking into logs | Full tokens left in URL parameters, access logs and monitoring | Never put tokens in URLs; redact them in logs |
| Long lifetimes | A leaked token stays usable for its whole lifetime | Use short access token lifetimes with a refresh mechanism |
| No active revocation | JWTs are stateless, so by default they cannot be withdrawn after issue | Keep a denylist or jti records, or shorten lifetimes |
Diagnosing "invalid token" in order
- Count the parts first. If it is not three, you probably missed a piece when copying, or the value carries a Bearer prefix, quotes or a line break.
- Decode the Header and confirm alg matches what the server expects.
- Decode the Payload, check whether exp has passed (seconds, not milliseconds), then check that iss and aud match the server configuration.
- Clock difference between server and client: a few minutes of skew can break an nbf or exp check, and servers typically allow a small tolerance.
- Verify the signature last: confirm the secret belongs to the right environment. Different production and test secrets are the most common cause.
Hands-on: why tampering with the payload breaks the signature
The most direct way to understand a signature is to break one yourself. Decode the second part of the example token, change role from editor to admin, Base64URL-encode it again and put it back as the second part, leaving the first and third parts untouched. Paste the new token into the JWT Parser: decoding succeeds and the payload plainly shows role as admin, but entering demo-secret in the verification area gives signature invalid.
The reason is that the third part was computed over the original two parts. Changing the second part changes the signed content, so the signature the server recomputes differs from the one carried in the token. To make a modified token pass, an attacker would need the secret to sign it again, which is exactly why the secret must stay confidential. The experiment also shows that a successful decode only means the format is right, never that the content can be trusted.
- Changing only the Header or only the Payload invalidates the signature either way.
- Re-encoding the whole token with unchanged content can still fail in a strict implementation if the text differs, for example by gaining padding equals signs.
- Strip the Bearer prefix from an Authorization header value first, otherwise it is judged to have the wrong number of parts or to fail decoding.
Cross-check the signature on the command line
If you would rather not depend entirely on a web page, compute it yourself with openssl and understand the details of HS256. Run this on the first two parts of the example token, kept exactly as they are including the dot between them:
printf '%s' 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzg0MjEiLCJuYW1lIjoiQWRhIExvdmVsYWNlIiwicm9sZSI6ImVkaXRvciIsImlhdCI6MTc2MDQwMDAwMCwiZXhwIjoxNzYwNDAzNjAwfQ' \
| openssl dgst -sha256 -hmac 'demo-secret' -binary \
| base64 | tr '+/' '-_' | tr -d '='The output is 32Ly9jxuicwBIgniALk2geoD2re8juuisCtiVCsT834, identical to the third part of the token. Two details are easy to get wrong. First, use printf rather than echo, because echo appends a newline and the signature will not match. Second, after Base64 you must swap + and / for - and _ and strip =, which is what makes it Base64URL. Run this once and the question of what exactly is signed disappears: it signs the text of the first two parts itself, not the decoded JSON.
JWT versus server-side sessions
| Dimension | JWT (stateless token) | Server-side session |
|---|---|---|
| Server storage | No need to store each token | Session data must be stored, and shared across instances |
| Horizontal scaling | Any instance can verify it given the secret | Needs shared sessions or sticky routing |
| Active revocation | Hard, needs a denylist or short lifetimes | Just delete the session |
| Payload size | Full token on every request, larger with more claims | Only a short session ID is sent |
| Information visibility | Payload readable by the holder | Data stays on the server |
| Good fit | Passing identity between services, short-term authorization | Admin systems that need forced logout or frequent permission changes |
A common compromise is a JWT access token with a very short lifetime (minutes to a few tens of minutes) plus a refresh token that is an opaque random string stored on the server and revocable at any time. You get the convenience of stateless verification and still keep the ability to revoke, at the cost of implementing a refresh flow.
One more reminder when troubleshooting: do not use a frontend exp check to decide whether to trust the user. Reading exp in the browser is only suitable for experience improvements, such as refreshing early when a token is about to expire or prompting a re-login. The actual allow or deny decision must be made by the server after verifying the signature, expiry, issuer and audience. Drawing that line clearly prevents most JWT-related incidents and saves detours while debugging.
When not to use JWT, or not to rely on this page alone
- Scenarios needing instant revocation, such as forced logout: server-side sessions are more direct, and JWTs need an extra denylist mechanism.
- Storing sensitive user data: JWTs are not encrypted by default. Use server-side storage or JWE.
- Verifying RS256, ES256 or other asymmetric signatures: this page does not support them. Use the JWT library of your language.
- Using the result as an authorization basis: any web tool is only for troubleshooting, and authorization must be done by the server.