JSON Web Tokens (JWTs) are everywhere in modern apps: logins, API access, single sign-on and mobile sessions. A JWT looks like a long random string, but it is actually three pieces of readable JSON, encoded and joined with dots. Understanding them makes authentication bugs much easier to fix.
Page Contents
The three parts
A JWT has the form xxxxx.yyyyy.zzzzz:
| Part | Contains | Example |
|---|---|---|
| Header | Token type and signing algorithm | {“alg”:”HS256″,”typ”:”JWT”} |
| Payload | Claims – data about the user and token | {“sub”:”42″,”exp”:1773484200} |
| Signature | Proof the header and payload were not changed | Created with a secret or private key |
The header and payload are Base64URL-encoded, not encrypted – see what is Base64. Anyone who has the token can read them.
Common claims
| Claim | Meaning |
|---|---|
| sub | Subject – usually the user ID |
| iss | Issuer – who created the token |
| aud | Audience – who the token is for |
| exp | Expiry time (Unix timestamp) |
| iat | Issued at |
| nbf | Not valid before |
| jti | Unique token ID |
Times are Unix timestamps in seconds – our JWT Decoder shows them as readable dates. See what is a Unix timestamp.
How verification works
- HS256 (HMAC): the server signs and verifies with the same secret. Simple, but every service that verifies must know the secret.
- RS256 / ES256: the issuer signs with a private key; anyone can verify with the public key. Common with identity providers and single sign-on.
A server must always verify the signature and the exp claim before trusting a token. Decoding is not verifying.
Security mistakes to avoid
- Putting secrets in the payload – it is readable by anyone.
- Accepting alg “none” or letting the token choose the algorithm – configure the expected algorithm on the server.
- Weak HS256 secrets – use a long random secret.
- Long-lived access tokens – keep them short (minutes) and use refresh tokens.
- Pasting production tokens into tools that send them to a server – a live token is a key to an account. Our decoder runs entirely in your browser.
Where to store JWTs
- Web apps: an HttpOnly, Secure, SameSite cookie protects the token from JavaScript (and XSS). localStorage is simpler but readable by any script on the page.
- Mobile apps: the platform’s secure storage – Android Keystore-backed storage or the iOS Keychain.
JWT vs session cookies
Session cookies store an ID and keep user data on the server; they are easy to revoke. JWTs carry data in the token and suit APIs and distributed systems, but revoking them before expiry needs extra work (short expiry, deny lists). Neither is always better.
FAQ
Is a JWT encrypted?
Usually not. Standard signed JWTs are only encoded; anyone can read the payload. Encrypted JWTs (JWE) exist but are less common.
How do I know if a JWT is expired?
Compare the exp claim with the current Unix time, or paste it into the decoder.
Can I decode a JWT without the secret?
Yes. The secret is only needed to verify the signature.
What does HS256 mean?
HMAC with SHA-256 – a signature using a shared secret.
Is it safe to paste my token into the decoder?
Ours decodes in your browser and sends nothing, but avoid sharing live production tokens anywhere.
Need a website or app for your business? Talk to Techpass Master – we design and build websites and apps for clients worldwide.
