A JWT, or JSON Web Token, is a small, self-contained package of data that proves who you are to a web server. When you log into an app and stay logged in across multiple pages or API calls, there's a reasonable chance a JWT is doing the work. It's one of the most widely used authentication mechanisms on the modern web, yet most Australians have no idea it exists.
The problem JWTs solve
Web servers are, by design, stateless. Each HTTP request arrives on its own, with no memory of whatever came before. That creates a problem: if you log in on request one, the server has forgotten you by request two.
The old answer was sessions. The server keeps a record of your login in memory or a database, hands you a session ID, and checks that ID on every subsequent request. It works. It also means every request hits the database, and if you're running multiple servers behind a load balancer, you need a shared session store to keep things consistent.
JWTs sidestep that entirely. The server issues a token containing your identity and signs it cryptographically. From that point on, the client carries the token and sends it with every request. The server verifies the signature without touching the database at all.
What's actually inside a JWT
A JWT has three parts, separated by dots. It looks like this:
xxxxx.yyyyy.zzzzz
Each part is Base64URL-encoded, which means it's readable if you decode it. The three parts are the header, the payload, and the signature.
The header declares the token type (JWT) and the signing algorithm used, most commonly HMAC SHA-256 (written as HS256) or RSA SHA-256 (RS256).
The payload holds the claims. Claims are statements about the user. Standard ones include sub (subject, usually a user ID), exp (expiry timestamp), and iat (issued-at timestamp). You can also add custom claims like a user's role or email address. The payload is not encrypted. Anyone who gets the token can read it. This is worth remembering.
The signature is what makes the whole thing trustworthy. The server takes the encoded header and payload, combines them, and runs them through a hashing algorithm using a secret key. The output is the signature. If anyone tampers with the payload, even a single character, the signature no longer matches and the server rejects the token.
How the login flow actually works
Here's the sequence in plain terms. You submit your username and password. The server verifies them against its database. It creates a JWT containing your user ID and an expiry time, signs it with its secret key, and sends it back to you. Your browser or app stores the token, usually in localStorage or an HTTP-only cookie. On every subsequent request, your client includes the token in the Authorization header as a Bearer token. The server checks the signature, confirms the token hasn't expired, and lets the request through. No database lookup required.
This is why JWTs are popular in distributed systems. A microservice receiving a request doesn't need access to your user database. It just needs the same signing key (or the corresponding public key in an asymmetric scheme) to verify the token independently.
The security trade-offs you need to understand
JWTs are not magic. They come with trade-offs that trip up developers who don't read past the sales pitch.
The biggest one is revocation. Because the server doesn't track issued tokens, it can't easily cancel one. If a user's JWT is stolen, or if an admin wants to force-logout a compromised account, the token stays valid until it expires. The fix is to keep expiry times short (15 minutes is common for access tokens) and pair the JWT with a longer-lived refresh token that can be revoked.
The payload is readable. Sensitive data doesn't belong there. Never put passwords, full payment details, or anything you'd be uncomfortable with a client seeing in a JWT payload. The signature proves the data wasn't tampered with; it doesn't hide it.
Algorithm confusion is a real attack class. Some early JWT libraries accepted a token that specified alg: none, effectively telling the server to skip signature verification entirely. Modern libraries have fixed this, but it's a reminder that JWT security depends heavily on correct implementation.
Storing JWTs in localStorage exposes them to cross-site scripting (XSS) attacks. Storing them in HTTP-only cookies protects against XSS but opens the door to cross-site request forgery (CSRF) if you're not careful. Neither option is perfect. Most serious applications combine HTTP-only cookies with CSRF tokens.
JWTs vs sessions: which one to use
Sessions are simpler to reason about and easier to revoke instantly. If you're building a traditional web app with a single server and a straightforward user base, sessions may be the cleaner choice.
JWTs shine in distributed architectures, single-page applications, and mobile apps where the client and server are clearly separated. They work well when you need multiple services to verify identity without coordinating through a central session store. This is why they're the default in most REST API and microservice designs.
The choice also depends on what else is on your stack. If you're already thinking about how public key infrastructure works in your system, asymmetric JWT signing (RS256) fits naturally into that model: the issuing service holds the private key, and any consuming service verifies using a distributed public key.
A practical note on expiry and refresh tokens
Short-lived access tokens (15 minutes) paired with longer-lived refresh tokens (7 to 30 days) is the standard pattern. The access token is what gets sent on every API request. When it expires, the client silently uses the refresh token to request a new access token. The refresh token lives in an HTTP-only cookie, reducing its exposure.
Refresh tokens can be stored server-side and revoked. This gives you the stateless efficiency of JWTs for most requests while preserving the ability to invalidate a session when it matters, such as after a password change or a security incident. Services like Auth0 have built entire products around this pattern, handling token issuance, rotation, and revocation so development teams don't have to.
Reading a JWT yourself
You can decode any JWT at jwt.io. Paste a token into the debugger and the payload immediately becomes readable plain text. This is a useful reminder that the payload is not secret. It's also a handy debugging tool when you're building an application and want to confirm what your server is actually issuing.
JWTs are compact, portable, and fast to verify. They've become the backbone of authentication across a huge slice of the modern web. Understanding what's inside the token, how the signature works, and where the limits lie puts you in a far stronger position to build or evaluate any system that uses them.

