On this page
You're debugging a login bug. The API returns 401, and you have a token in your clipboard that starts with eyJ. You search for "decode jwt", click the first result, and paste.
That token might still be valid. Depending on the site, you may have just sent a working credential for your production system to a server you know nothing about.
The good news: you never need to send a JWT anywhere to read it. Decoding one is a few lines of code. Here's how it works, and how to do it safely.
What's actually inside a JWT
A JSON Web Token is three pieces joined by dots:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0IiwibmFtZSI6IkFkYSIsImV4cCI6MTc5NTE5NjM4NH0.4pcPyMD09olPSyXnrXCjTwXyr4BsezdI1AVTmud2fU4Split on the dots, it's:
header eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
payload eyJzdWIiOiIxMjM0IiwibmFtZSI6IkFkYSIsImV4cCI6MTc5NTE5NjM4NH0
signature 4pcPyMD09olPSyXnrXCjTwXyr4BsezdI1AVTmud2fU4- Header: which algorithm signed the token, such as
HS256orRS256. - Payload: the claims: who the user is, when the token expires, and anything else the issuer added.
- Signature: proof that the header and payload haven't been changed.
The header and payload are Base64URL-encoded JSON. They are encoded, not encrypted. Anyone who has the token can read them. Only the signature needs a key, and you don't need the signature to read the token.
Decode it in your browser console
Open DevTools on any page (or about:blank) and paste:
function decodeJwt(token) {
const [header, payload] = token.split(".").slice(0, 2).map((part) => {
const base64 = part.replace(/-/g, "+").replace(/_/g, "/");
const bytes = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
return JSON.parse(new TextDecoder().decode(bytes));
});
return { header, payload };
}
decodeJwt("eyJhbGciOi...");Two details make this correct instead of almost correct:
- Base64URL is not Base64. JWTs use
-and_instead of+and/, and they drop the=padding. Thereplacecalls put the standard characters back. Browsers'atobaccepts the missing padding. - Payloads can contain non-ASCII text, like a user's name in Bengali or Japanese.
atobalone returns raw bytes as a string and will mangle it.TextDecoderreads it as UTF-8.
Decode it in Node.js
Node has Base64URL built in:
const [header, payload] = token
.split(".")
.slice(0, 2)
.map((part) => JSON.parse(Buffer.from(part, "base64url").toString("utf8")));Decode it in the terminal
With jq installed:
jq -R 'split(".") | .[0:2] | map(gsub("-";"+") | gsub("_";"/") | @base64d | fromjson)' <<< "$TOKEN"The two gsub calls do the same Base64URL-to-Base64 swap as the browser version. Tested with jq 1.7.
Reading the claims
Most payloads use a handful of registered claims:
| Claim | Meaning | Watch out for |
|---|---|---|
sub | Subject: usually the user ID | — |
iss | Issuer: who created the token | Check it matches your auth server |
aud | Audience: who the token is for | A token for one API shouldn't work on another |
exp | Expiry time | Seconds since 1970, not milliseconds |
iat | Issued at | Also seconds |
nbf | Not valid before | Clock drift between servers can trip this |
The seconds-versus-milliseconds trap catches everyone once. Date.now() in JavaScript returns milliseconds, so compare like this:
const isExpired = payload.exp * 1000 < Date.now();If your token "expires immediately" or "never expires", this is the first thing to check.
Decoding is not verifying
Reading a token tells you what it claims. It doesn't tell you the claims are true. Anyone can write a payload that says "role": "admin", encode it, and attach a junk signature.
Your server must verify the signature with the right key before it trusts anything in the payload. Use a maintained library for this, not a hand-written check, and be strict about it:
- Pin the algorithm. Tell the library which algorithm you expect, such as
RS256. Never let the token's own header choose. - Reject
alg: "none". Unsigned tokens are a classic attack. Good libraries refuse them by default, but check. - Check
exp,nbf,issandaud, not just the signature.
Decoding is for debugging and for showing information in a UI. Verifying is for deciding whether to trust a request.
Why pasting tokens into websites is risky
A JWT is usually a bearer token: whoever holds it can use it until it expires. Access tokens often live for 15 minutes to an hour; refresh tokens can last days or weeks.
When you paste a token into an online decoder, one of two things happens:
- The site decodes it in your browser. Nothing leaves your machine. This is fine.
- The site sends it to its server. Now a live credential sits in someone else's request logs, analytics, or error tracker.
You usually can't tell which from the page itself. You can check:
- Open DevTools and go to the Network tab.
- Clear it, then paste your token.
- If a new request appears that carries your input, the tool is uploading it.
utilyx's JWT decoder runs entirely in your browser. You don't have to take our word for it: run the Network-tab test above, or load the page, switch your connection off, and decode a token offline.
A safe debugging routine
- Prefer expired or test tokens when you share a decoded token with teammates or paste it into a bug report.
- Redact before sharing. Remove the signature (the part after the second dot) and any personal data from the payload.
- Never put tokens in URLs you share. They end up in browser history and server logs.
- Rotate if in doubt. If a production token was pasted somewhere it shouldn't have been, revoke the session.
Quick reference
- A JWT is
header.payload.signature. The first two parts are Base64URL-encoded JSON. - Decoding needs no key. Verifying does.
exp,iatandnbfare in seconds.- Treat any live token like a password.
Try it: paste a token into the utilyx JWT decoder to see its header, payload, and exactly when it expires, without it leaving your browser.