A 401 Unauthorized response tells you almost nothing on its own. The request reached the server, the server looked at the token, and something about it failed. That something is usually one of a short list: the token expired, the token is not the one you think you sent, or the signature does not check out. Two of those three are written inside the token itself, in plain sight, if you decode it. This guide works through the list in order with the JWT Decoder on Ovatly, and is honest about the point where the decoder's usefulness ends.

Contents

  • Quick answer
  • The three usual causes of a token 401
  • How to debug the token, step by step
  • Worked example: reading the demo token like a failing one
  • Limitations: the failure only the server can see
  • Common mistakes
  • FAQs
  • Conclusion

Quick answer

Decode the token first. Paste the full token, all three dot-separated parts, into the JWT Decoder and check three things: the expiry panel's verdict (expired or not expired), the iat and exp values behind it, and the sub and iss claims, which tell you whose token this is and who issued it. If the verdict is expired, refresh or re-login and you are done. If every claim looks right, the failure is almost certainly the signature, and that is a server-side finding: the decoder cannot verify signatures, because it does not have the signing key or the issuer's public key.

The three usual causes of a token 401

Expiry is the most common cause and the easiest to confirm. Tokens carry an exp claim, seconds since the Unix epoch, and servers reject tokens whose time has passed. The catch is that epoch seconds are unreadable at a glance, so developers often skip the check or misread the number. The decoder exists partly to remove that excuse: it translates the expiry into a readable date and states the verdict in words.

The second cause is the wrong token. Development environments breed stale tokens: an old one cached in the browser, a test token sent to production, a token for a different user than the one being tested. The sub and iss claims expose this immediately. If sub is not the user you expected, or iss names a different issuer than the API expects, the server is right to return 401 and the fix is in your client, not your auth code.

The third cause is the signature. The server recomputes or checks the signature against its key, and any mismatch means rejection: a payload edited after signing, a key rotated on the server, a token signed by a different environment. This cause is real and frequent, and it is the one a decoder cannot see, for reasons the limitations section covers.

How to debug the token, step by step

  1. Open the JWT Decoder and paste the full token, all three dot-separated parts, exactly as the client sent it.
  2. Read the decoded header, which names the algorithm and token type, and note anything unexpected there.
  3. Read the payload claims: check sub against the user you expected, iss against the issuer the API trusts, and iat for when the token was issued.
  4. Check the expiry panel for the verdict. If it says expired, note the date it gives you; that is when the token stopped being acceptable.
  5. If the claims are all correct and the token is not expired, stop debugging the token's contents. The remaining suspect is the signature, and only the issuing server can confirm or clear it.

Worked example: reading the demo token like a failing one

Take the well-known demo token as a stand-in for one pulled from a failing request. Its header is {"alg":"HS256","typ":"JWT"}. Its payload contains sub "1234567890", name "John Doe" and iat 1516239022. Reading it the debugging way: the algorithm is HS256 as expected, the subject claim says 1234567890, and the issued-at claim is the epoch value 1516239022, a token issued a long time ago in real terms.

The demo payload carries no exp claim, and the tool reports that plainly: the token has no expiry of its own. In a real 401 investigation that finding redirects you. Expiry cannot be the cause of a rejection for a token with no expiry, so you move to the issuer claim and then to the signature. Add an exp claim of 4000000000 to the same payload and the panel changes completely: it reports expiry on 2 October 2096 and a not-expired verdict. Now expiry is cleared with a date you can quote, and again the signature is what remains. That is the rhythm of this debugging method: each claim you read either names the fault or removes a suspect, until only the server-side check is left.

Limitations: the failure only the server can see

Decoding is not verification. Without the signing key or the issuer's public key, nobody can confirm a token is genuine, and this tool never claims to. The signature segment is shown as present but not verified. So a token can decode perfectly, carry sensible claims and a future expiry, and still be correctly rejected because its signature was made with the wrong key. If your debugging reaches that point, the next step is on the issuer's side: server logs, the key configuration, the environment that minted the token.

Two softer edges matter too. The tool reports the exp claim exactly, but the server's policy decides enforcement: some systems allow clock skew leeway of a minute or two, and some ignore exp for specific flows, which is why a borderline token can fail on one service and pass on another. And everything in this workflow happens locally in your browser; the page never uploads the token you paste, which matters because the token from a failing request is a live credential until it expires.

Common mistakes

  • Guessing at epoch numbers. exp and iat are seconds since the Unix epoch. A misread digit sends you debugging the wrong cause. Let the tool translate them.
  • Debugging a different token than the one sent. Copy the token from the actual failing request, not from memory, an old tab or a test script.
  • Pasting a truncated token. The decoder needs all three dot-separated parts; a fragment copied from a wrapped log line will not decode usefully.
  • Assuming a clean decode means the server is wrong. The server also verified the signature, a check you have not performed and cannot perform without the key.
  • Treating no expiry as an error. Some tokens legitimately carry no exp claim. The tool reports that state instead of inventing a verdict, and your 401 cause lies elsewhere.

FAQs

What is the first thing to check when a request returns 401? The token itself. Decode it and read the expiry panel: if the verdict is expired, you have found the most common cause. Then check the iat and exp values and the sub and iss claims to confirm the token is the one you think you sent.

My token decodes fine. Why does the server still reject it? Decoding only shows what a token claims. The server also verifies the signature, and a decoder cannot do that without the signing key or the issuer's public key. If the claims look correct, a signature or issuer-policy failure is the likely cause, and only the issuer's side can confirm it.

The decoder says expired but the app sometimes accepts the token. Why? Some systems allow clock skew leeway of a minute or two, and some ignore exp for specific flows. The tool reports the claim exactly; your server's policy decides what is enforced, so borderline expiry can behave inconsistently.

What if my token has no exp claim at all? Tokens without an exp claim are reported as having no expiry of their own, which is common for some API tokens. In that case expiry is not your 401 cause; look at the subject and issuer claims, and then at the signature, which only the server can judge.

Can this tool tell me whether my signature is valid? No. Verification needs the secret or public key used to sign the token, which a decoder page does not have. This tool decodes and labels the signature as not verified, so treat a clean decode as the start of debugging, not the end.

Conclusion

A token-caused 401 is usually diagnosable in a minute: decode with the JWT Decoder, read the claims, take the expiry verdict, and you either find the fault or narrow it to the signature, the one check only the issuer can run. Before you paste a live token anywhere, though, it is worth knowing exactly what a decoder can and cannot see; the companion guide covers that ground: Is It Safe to Decode a JWT Online?.

More tools for this kind of work live in the Developer Tools archive.