What a JWT Actually Contains, and Why Decoding One Is Not Verifying It
A field-by-field look inside a JSON Web Token, why anyone can decode it, what verification really checks, and where tokens leak in practice.
Three pieces of text, readable by anyone
A JSON Web Token looks opaque: a long string of letters and digits split by two dots. It is not opaque at all. The first two parts are JSON objects encoded with Base64URL, which is a reversible text encoding, not encryption. Anyone who holds the token can read every field in it without a key.
The third part is a signature. It is what makes the token trustworthy, and it is the part most debugging sessions ignore. Decoding a token tells you what it claims. Verifying it tells you whether those claims were issued by someone you trust and have not been altered. Confusing the two is behind a long list of real authentication bugs.
Anatomy of a token
Here is a token built for this article, signed with HS256 and a throwaway secret. It is split into its three parts for readability; in practice they are joined with dots.
Header: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
Payload: eyJpc3MiOiJodHRwczovL2F1dGguZXhhbXBsZS5jb20iLCJzdWIiOiJ1c2VyXzg0MTIiLCJhdWQiOiJhcGkuZXhhbXBsZS5jb20iLCJpYXQiOjE3OTI1NDA4MDAsIm5iZiI6MTc5MjU0MDgwMCwiZXhwIjoxNzkyNTQxNzAwLCJyb2xlIjoiZWRpdG9yIn0
Signature: 0Vf1R56obB4P-IsSvqCz_gHa5l-HidWDeHdWppKjbPU
Decoded, the header is {"alg":"HS256","typ":"JWT"}. It names the signing algorithm and the token type. The payload is {"iss":"https://auth.example.com","sub":"user_8412","aud":"api.example.com","iat":1792540800,"nbf":1792540800,"exp":1792541700,"role":"editor"}. The signature is 32 raw bytes (the output of HMAC-SHA256), which Base64URL turns into 43 characters.
Paste the full token into the JWT Decoder and you will see the header and payload as formatted JSON, plus the exp claim converted to a UTC date. Notice that nothing in that process needed the secret. That is the whole point of this article.
Base64URL is not quite Base64
Standard Base64 uses + and / and pads the output with = signs. Those characters are awkward in URLs and HTTP headers, so JWTs use the Base64URL variant: + becomes -, / becomes _, and the padding is dropped. For example, the text <<???>> encodes to PDw/Pz8+Pg== in standard Base64 and PDw_Pz8-Pg in Base64URL.
This matters when you decode a segment by hand. The Base64 Encoder / Decoder on this site works with standard Base64, so to decode a JWT segment with it, replace each - with + and each _ with / first. Browsers' Base64 decoding generally accepts missing padding, but some other decoders do not, in which case add = characters until the length is a multiple of four. The JWT Decoder does the character swap for you.
One more detail trips up hand-written decoders: the decoded bytes are UTF-8 text. A naive decode that treats each byte as a character turns a claim like a name with accents or a non-Latin script into garbage, even though the token is fine. Decode the bytes as UTF-8 before parsing the JSON. The JWT Decoder does this, so names and other claims in any script display correctly.
The registered claims and what each should trigger
The JWT specification (RFC 7519) defines a handful of registered claim names. None of them is mandatory, but if they are present, the receiving server is expected to act on them. Decoding shows you the values; it does not enforce any of them.
| Claim | Meaning | What the verifier should do |
|---|---|---|
| iss | Issuer: who created the token | Reject tokens from any issuer it does not explicitly trust |
| sub | Subject: usually the user or client ID | Use as the identity only after the signature checks out |
| aud | Audience: who the token is intended for | Reject tokens meant for a different service or API |
| exp | Expiry time, in seconds since the Unix epoch | Reject if the current time is past exp (allowing small clock skew) |
| nbf | Not before: earliest valid time | Reject if the current time is before nbf |
| iat | Issued at | Optional checks, such as rejecting tokens issued before a password change |
| jti | Unique token ID | Supports revocation lists and replay detection |
Reading the time claims
exp, nbf and iat are NumericDate values: whole seconds since 1970-01-01T00:00:00Z, not milliseconds. In the example, iat and nbf are 1792540800, which is 2026-10-21 00:00:00 UTC, and exp is 1792541700, fifteen minutes later. You can check any of these values in the Unix Timestamp Converter, which shows the UTC, local and ISO 8601 form of a timestamp.
Two practical problems show up here. First, JavaScript's Date works in milliseconds, so code that passes exp straight to new Date() gets a date in January 1970 and treats every token as long expired; multiply by 1000 first. Second, servers disagree about the time. A token issued by one machine can look 'not yet valid' to another whose clock is a few seconds behind. Most libraries let you allow a small leeway for this. Keep it to seconds, not hours.
Signatures: who can create a token and who can check it
The alg header names how the signature was made. The three you will meet most often behave very differently.
| Algorithm | Key type | Who can sign | Who can verify | Signature length (Base64URL) |
|---|---|---|---|---|
| HS256 (HMAC with SHA-256) | One shared secret | Anyone with the secret | Anyone with the same secret | 43 characters (32 bytes) |
| RS256 (RSA with SHA-256) | Private and public key pair | Only the private key holder | Anyone with the public key | 342 characters with a 2048-bit key (256 bytes) |
| ES256 (ECDSA P-256 with SHA-256) | Private and public key pair | Only the private key holder | Anyone with the public key | 86 characters (64 bytes) |
What verification actually involves
With HS256, every service that verifies tokens holds the same secret, which means every one of them could also mint tokens. That is acceptable inside a single application and risky across many services. With RS256 or ES256, only the identity provider holds the private key, and any service can verify using the public key, often published at a JWKS endpoint.
Verification is two steps, and skipping either one breaks security. First, recompute or check the signature over the exact header and payload text, using a key and algorithm the server chose in advance. Second, validate the claims: issuer, audience, expiry and not-before. Many libraries offer both a decode function and a verify function. The decode function exists for debugging and for reading the header to pick a key. Using it to make an access decision means accepting whatever an attacker writes in the payload.
Pitfalls that come from trusting the header
The header is part of the token, which means it is attacker-controlled until the signature is checked. Several classic vulnerabilities come from letting the header decide how verification works.
- alg none: the JWS specification defines an unsecured 'none' algorithm with an empty signature. Libraries that honoured it when it appeared in a token header would accept a forged token with no signature at all. Never allow none in production.
- Algorithm confusion: a server expects RS256 and passes its RSA public key to a generic verify function. An attacker changes the header to HS256 and signs the token with HMAC, using the public key (which is public) as the secret. A library that follows the header will verify it successfully. The fix is to pin the expected algorithm in server code.
- Weak HS256 secrets: anyone with one valid token can try candidate secrets offline as fast as their hardware allows, with no rate limit. Use a long random secret, not a word or a project name.
- Untrusted key hints: headers such as kid and jku tell the server which key to use or where to fetch it. Treat them as lookups into a list you control, never as file paths, database queries or arbitrary URLs.
- Missing audience checks: a validly signed token issued for one service is replayed against another service that trusts the same issuer.
Where tokens leak
A JWT used as a bearer token is a credential. Whoever presents it is treated as its owner until it expires, and most JWTs cannot be revoked individually without extra infrastructure. The common leak paths are mundane.
- Query strings: tokens in URLs end up in server access logs, proxy logs, browser history and Referer headers.
- Application logs and error trackers that record full request headers.
- Browser storage readable by JavaScript, where a single cross-site scripting bug exposes it.
- Screenshots, support tickets, chat messages and bug reports.
- Online decoders: pasting a live production token into an unknown website hands the credential to whoever runs it.
Decoding safely
If you must inspect a real token, decode it locally. The JWT Decoder on this site is a client-side component: it splits the token, decodes the first two parts with the browser's own Base64 and UTF-8 decoders and JSON parser, and displays the result. The token is not sent to a server. You do not have to take that on trust: open your browser's developer tools, watch the Network tab while you paste a token, and confirm that no request is made. For the most sensitive tokens, decoding on your own machine in a terminal is better still, and the safest habit of all is to debug with short-lived test tokens.
If a production token has been pasted somewhere it should not have been, treat it as compromised: let it expire if the lifetime is short, otherwise revoke the session or rotate the signing key.
When you need to correlate tokens in logs without storing them, log a fingerprint instead. A SHA-256 hash of the token identifies it uniquely without being usable as a credential. The Cryptographic Hash Generator computes SHA-256, SHA-512 and SHA-1 digests for this kind of check. Note that it computes plain hashes, not HMACs, so it cannot be used to verify an HS256 signature.
A debugging checklist
- Decode the header: is alg the algorithm your server is configured to accept?
- Decode the payload: do iss and aud match exactly, including scheme and trailing slashes?
- Convert exp, nbf and iat to dates and compare them with the server's clock, not your laptop's.
- Check whether the code calls a verify function or only a decode function.
- Confirm the key: right secret or public key, and the right kid if keys rotate.
- If the token has five parts instead of three, it is an encrypted JWE. Only its protected header is readable; the payload cannot be read without the decryption key. The JWT Decoder recognises this case and shows the header on its own.
Frequently asked questions
Is the data inside a JWT encrypted?
Not in the usual signed JWT. The header and payload are only Base64URL-encoded, so anyone holding the token can read them. Do not put secrets or sensitive personal data in a signed token. Encrypted tokens (JWE) exist and have five parts instead of three; only their header can be decoded without the key.
Can a JWT decoder tell me whether a token is valid?
No. A decoder shows what the token claims. Validity requires checking the signature with the correct key and algorithm, then checking issuer, audience and time claims. The JWT Decoder on this site decodes and shows the expiry date; it does not verify signatures.
Why does my token show an expiry date in 1970?
JWT time claims are in seconds, but JavaScript dates use milliseconds. Passing exp directly to new Date() treats it as milliseconds and lands in January 1970. Multiply by 1000 first.
Is it safe to paste a JWT into an online decoder?
Only if the decoder runs entirely in your browser, and even then it is better to use test tokens. A live token is a credential until it expires. You can confirm that a decoder makes no network requests by watching the Network tab in developer tools.
Should I use HS256 or RS256?
HS256 is simpler when one application both issues and verifies tokens. RS256 or ES256 is better when several services verify tokens, because they only need the public key and cannot mint tokens themselves.