JWT vs Session Cookies
A session cookie holds a meaningless identifier and the server looks up the real state. A JWT carries the claims themselves, signed so the server can trust them without a lookup. Sessions are trivial to revoke but need shared storage. JWTs scale across services but cannot be withdrawn before they expire. Most single applications are better served by sessions.
JWT Decoder
Read a JSON Web Token header, payload and expiry.
This is usually presented as old versus modern, which is the wrong frame. It is a straight trade: sessions keep state on the server and get instant revocation; JWTs move state to the client and get statelessness. Neither is free.
The question that settles it in practice is what happens when you need to log someone out immediately — a compromised account, a sacked employee, a withdrawn permission. Sessions handle that in one delete. JWTs, by design, do not.
How each one works
- Session cookie: the cookie holds a random opaque ID. Every request looks the session up in shared storage to find who the user is.
- JWT: the token holds the claims — user ID, roles, expiry — signed with a key. The server verifies the signature and trusts the contents without a lookup.
Revocation, the deciding factor
A session is revoked by deleting it: the next request fails immediately. A JWT stays valid until it expires, because verification is a signature check with nothing to consult. The usual answer is short-lived access tokens plus a refresh token — but that means a lookup on refresh, which is server state again, arrived at by a longer route. If you need immediate revocation and are not building across services, sessions do it more simply.
Where JWTs genuinely win
When several independent services must authenticate the same user without sharing a session store. Each verifies the signature with a public key and needs no network call and no shared database. That is the problem JWTs were designed for, and for it they are the right answer.
- Multiple services or teams that cannot share session storage.
- Third-party API access, where OpenID Connect issues tokens anyway.
- Short-lived, single-purpose tokens such as a signed download link.
- Server-to-server authentication with no browser involved.
Where sessions genuinely win
A single application with one datastore — which describes most software. Sessions are simpler, revocation is instant, the cookie carries no data worth stealing, and changing a user's permissions takes effect on the next request rather than on the next token refresh. The storage cost is a Redis key.
Storage, and the mistake that matters
Whichever you choose, keep the credential in an HttpOnly, Secure, SameSite cookie. Storing a JWT in localStorage is the most common security mistake in this area: any injected script can read it, and unlike a session cookie it carries its own authority wherever it is replayed. A JWT in a cookie is fine. A JWT in localStorage turns every XSS into a full account takeover.
Frequently asked questions
Can I revoke a JWT?
Are JWTs more scalable than sessions?
Where should I store a JWT in a browser?
Is a JWT encrypted?
Can I use both?
Tools used in this guide
All tools →- JWT Decoder Read a JSON Web Token header, payload and expiry. In your browser
- HMAC Generator Sign a message with a secret key using HMAC. In your browser
- UUID Generator Generate random v4 or time-ordered v7 UUIDs in bulk. In your browser
- Unix Timestamp Converter Convert between Unix timestamps and human dates. In your browser
- Base64 Encoder and Decoder Encode text to Base64 or decode it back, including URL-safe. In your browser
- HTTP Header Parser Turn a raw header block into a readable table. In your browser
Related guides
All guides →- How to Decode a JWT Read the header and payload of a JSON Web Token, check its expiry, and understand why decoding is not verifying.
- How to Verify a Webhook Signature Reproduce an HMAC signature correctly, and find out why yours does not match.
- Hashing vs Encryption One-way versus two-way, and why using the wrong one is a security bug.
Last reviewed .