A JWT (JSON Web Token) is a compact, URL-safe string that carries a set of claims, such as a user ID and an expiry time, from one party to another. RFC 7519 defines it.
A signed JWT has three parts separated by dots: header, payload and signature. Anyone holding the token can read the header and payload. The signature lets a server detect changes, if the server checks it correctly.
What is JWT?
JWT is the token format many APIs accept after login, usually in an Authorization: Bearer header. Most JWTs are JSON Web Signatures (JWS): the claims stay readable and a signature protects them from edits.
A JSON Web Encryption (JWE) token also hides the claims. When people ask “what is JWT authentication”, they usually mean the signed form.
What does a JWT look like? A JWT token example
Here is a simplified example, signed with HS256 and a random 32-byte key:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzEyMyIsImF1ZCI6Im9yZGVycy1hcGkiLCJpYXQiOjE3OTU3NDIyNjUsImV4cCI6MTc5NTc0MzE2NSwiaXNzIjoiaHR0cHM6Ly9hdXRoLmV4YW1wbGUuY29tIn0.fBnAtqyBzP0Sp-S5i_PpjyB1jdZUFgH8F1DUwePIShA
In the JWT token format, the first two parts are base64url-encoded JSON, and decoding them needs no key:
header: {"alg":"HS256","typ":"JWT"}
payload: {"sub":"user_123","aud":"orders-api","iat":1795742265,"exp":1795743165,"iss":"https://auth.example.com"}
Some guides say a token is unreadable without the signing key. For a signed JWT that is wrong: base64url is a plain encoding round trip. Anyone can read this payload, so keep passwords and personal data out of it.

Two parts anyone can read, one part that shows tampering.
RFC 7519 section 4.1 registers seven claim names. None is mandatory; your application picks the ones it needs.
| Claim | Name | What it means |
|---|---|---|
iss |
Issuer | Who created and signed the token |
sub |
Subject | Who the token is about, usually a user ID |
aud |
Audience | Which service the token is for |
exp |
Expiration time | Reject the token after this time |
nbf |
Not before | Reject the token before this time |
iat |
Issued at | When the token was created |
jti |
JWT ID | A unique ID, useful against replays |
Time claims count seconds since 1970 UTC, so this JWT example lives for 900 seconds.
How the JWT signature works
The signature covers the encoded header and payload. RFC 7518 section 3.1 lists the algorithms, and the common ones all use SHA-256. HS256 is HMAC with SHA-256: one shared secret signs and verifies, so every service that can check a token can also mint one.
RS256 (RSA) and ES256 (ECDSA with P-256) use a key pair. The issuer keeps the private key and publishes the public key, so other services can check tokens but cannot create them.
An HS256 key must be at least 256 bits (RFC 7518 section 3.2), and RFC 8725 section 3.5 forbids using a human-memorable password as the key. With a weak secret, anyone who captures one token can brute-force the key offline. Many webhooks sign the raw request body with a shared secret; see our webhook vs API guide.

Many services can check the seal; only the issuer holds the press.
How to validate a JWT
RFC 8725 (BCP 225, February 2020) is the current best-practice document. As of November 27, 2026, its revision, draft-ietf-oauth-rfc8725bis-10, sits in the RFC Editor queue and is not yet an RFC. The section numbers below match both.
- Pin the algorithm. Accept a fixed list, use each key with exactly one algorithm (section 3.1), and never let the token’s
algheader choose. - Verify the signature with the key you expect for that issuer, and reject the token if any check fails (section 3.3).
- Check
iss, and confirm the key belongs to that issuer (section 3.8). - Check that
audnames this service. If one issuer serves several apps, reject a missing or different audience (section 3.9). - Check
expandnbfwith small clock skew. RFC 7519 suggests “no more than a few minutes”. - Check
typwhen you issue more than one kind of JWT (section 3.11).
With jsonwebtoken 9.0.3, the current npm release, steps 1 to 5 look like this:
const payload = jwt.verify(token, key, {
algorithms: ['HS256'],
issuer: 'https://auth.example.com',
audience: 'orders-api',
clockTolerance: 30,
});
On Node.js 22 this returned user_123 for the example token. With audience: 'billing-api' it threw jwt audience invalid. A token expired 10 seconds earlier failed with jwt expired until clockTolerance was set.
The library does not check typ; pass complete: true and compare the header yourself.
What goes wrong when you skip a step
A token with alg: none has no signature. RFC 8725 says libraries should accept one only when the caller asks. jsonwebtoken stopped accepting unsigned tokens by default in 9.0.0 (December 21, 2022), and the test above rejected one with jwt signature is required.
According to NVD, CVE-2015-9235 let attackers bypass verification in jsonwebtoken before 4.2.2: a server expecting RS or ES tokens accepted one signed with an HS algorithm. The pinned list in step 1 blocks this. In the same test, a token HMAC-signed with an RSA public key as the secret failed with invalid algorithm.
Skipping step 4 lets a valid token for billing-api work against orders-api when both trust the same issuer. RFC 8725 section 2.7 calls these substitution attacks.

A token for another service should not open this door.
JWT or server session?
JWTs are still in wide use. OpenID Connect ID tokens are JWTs, and RFC 9068 notes that many commercial OAuth servers issue JWT access tokens.
The main cost is revocation: a server accepts a signed JWT until exp, so logout does not stop a token already issued unless you keep a deny list keyed by jti, which brings back a lookup per request.
A session cookie holds a random ID that the server can delete at once. For one web app and its own backend, a session is usually simpler. JWTs pay off when several services check identity without calling the issuer, for example at a reverse proxy or gateway.
After validation, sub is a natural key for rate limiting, and retried writes still need idempotency keys.
Is JWT a type of OAuth?
No. OAuth 2.0 is an authorization framework and JWT is a token format. RFC 6749 does not mandate any access token format.
RFC 9068 (October 2021) defines a JWT profile for OAuth 2.0 access tokens with the typ value at+jwt, which helps resource servers reject ID tokens sent as access tokens.



