What Is a JWT? JSON Web Tokens Explained Simply
XUtilHub Team ·
If you've built or used a modern login system, you've met a JWT: a long string of letters, numbers and two dots, sent with every request. Here's what's inside, how it's protected, and the mistakes that lead to security holes.
What a JWT looks like
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0IiwibmFtZSI6IkFsaSIsImV4cCI6MTc5MzY5NjAwMH0.Xb3k...
It has three parts separated by dots: header, payload and signature. The first two are just JSON encoded with Base64URL, so anyone can read them. Paste a token into the JWT decoder to see.
1. Header
{ "alg": "HS256", "typ": "JWT" }
Says which algorithm signed the token.
2. Payload (claims)
{ "sub": "1234", "name": "Ali", "role": "admin", "exp": 1793696000 }
Common registered claims:
| Claim | Meaning |
|---|---|
sub | Subject: usually the user ID |
iat | Issued at (Unix timestamp) |
exp | Expires at (Unix timestamp) |
nbf | Not valid before |
iss | Issuer: who created the token |
aud | Audience: who the token is for |
3. Signature
The server signs the header and payload with a secret key (HS256) or a private key (RS256, ES256). When the token comes back, the server recalculates the signature. If anyone changed even one character of the payload, say "role": "user" to "role": "admin", the signature no longer matches and the token is rejected.
Signed is not encrypted
This is the most important thing to understand: anyone can read a JWT's payload. The signature stops tampering, not reading. Never put passwords, ID numbers or other secrets in a JWT.
Common security mistakes
- Weak HS256 secrets. A short or guessable secret can be brute-forced offline from a single token. Use at least 256 random bits; the secret key generator creates one.
- Accepting
alg: noneor letting the token choose its algorithm. Always verify with the algorithm your server expects. - No expiry, or very long expiry. Keep access tokens short-lived (minutes to an hour) and use refresh tokens for longer sessions.
- Storing tokens where scripts can read them. Tokens in localStorage can be stolen by any XSS bug. HttpOnly cookies are safer for browser apps.
- Forgetting revocation. A JWT is valid until it expires, even after logout. Short expiry or a denylist solves this.
JWT vs session cookies
Traditional sessions store a random ID in a cookie and keep the data on the server. JWTs carry the data inside the token, so servers don't need to look anything up, which helps with APIs and multiple services. Neither is automatically more secure; it depends on how they're implemented.
Decode one
The JWT decoder shows the header and payload, converts exp and iat into readable dates, and works in your browser, so the token isn't sent anywhere. For the encoding itself, see the Base64 encoder/decoder.
Tools mentioned in this article
JWT Decoder
Decode JWT tokens online and view the header, payload and claims. See issued-at and expiry times in readable form. Nothing is uploaded.
Base64 Encode / DecodeNEW
Encode text to Base64 or decode Base64 to text, with full UTF-8 and emoji support and a URL-safe option. Free and private.
Secret Key GeneratorNEW
Generate cryptographically secure random keys for APIs, JWT secrets, session secrets and encryption, in hex, Base64 or Base64URL.