JWT Cheat Sheet: Claims, Algorithms and Validation
Checked against JSON Web Token RFC 7519, 7515, 7518, 8037, 8725; examples with PyJWT 2.15.1 on 28 November 2026. Each section links to the official docs it was checked against.
This sheet is for backend developers who issue or verify JWTs and want the rules from the RFCs, not from a tutorial. It covers RFC 7519 (JWT), RFC 7515 (JWS), RFC 7518 (algorithms), RFC 8037 (EdDSA) and the RFC 8725 best practices. The code examples were run with PyJWT 2.15.1 in Python 3.12.
When to use what
Pick HS256 only when the same service both issues and verifies the token. HMAC uses one shared secret, so every verifier can also mint tokens. As soon as a second service needs to verify, switch to a public-key algorithm so verifiers only hold the public key.
Among public-key algorithms, RS256 has the widest library support and RFC 9068 requires it for JWT access tokens. ES256 gives much smaller signatures (64 bytes in our test) and RFC 7518 marks it Recommended+, meaning its status is expected to rise. EdDSA with Ed25519 is the modern choice when every library in your stack supports it; RFC 8037 lists it as optional, so check first.
The algorithm matters less than the verification code. Most real JWT bugs are a verifier that trusts the token's own alg header, skips aud, or accepts tokens that live for days. Our JWT security best practices guide and the post on JWT security mistakes go deeper. To look inside a token, use the JWT decoder; never paste production tokens into a site that sends them to a server.
Base64url uses - and _ instead of + and / and drops the = padding. The payload is only encoded, not encrypted: anyone holding the token can read it.
header.payload.signatureCompact JWS form: three base64url parts joined by dots
{"alg":"HS256","typ":"JWT"}Typical header; alg is required and must be understood by the verifier
kidHeader hint naming which key signed the token, used to pick a key from a JWKS
jku / x5uHeader URLs pointing at keys or certs; never fetch them blindly, they are an SSRF and key-injection risk
critHeader listing extensions the verifier must understand or reject the token
header.payload.An unsecured token with alg none ends with an empty signature
All seven are optional in RFC 7519 itself; profiles like OIDC and RFC 9068 make some of them required. Times are NumericDate: seconds since 1970-01-01 UTC.
issIssuer; compare it exactly against the issuer you trust
subSubject, usually a user ID unique within the issuer
audAudience, a string or array; a service not listed must reject the token
expExpiry time; reject when now is at or after it, allowing a few minutes of clock skew at most
nbfNot-before time; reject tokens used too early
iatIssued-at time, used to work out the token's age
jtiUnique token ID, for replay detection or a deny list
EdDSA is defined in RFC 8037 (https://www.rfc-editor.org/rfc/rfc8037). RFC 7518 requires RSA keys of 2048 bits or more.
HS256HMAC with SHA-256 and a shared secret of at least 32 bytes; the only algorithm RFC 7518 makes required
RS256RSA PKCS#1 v1.5 signature with SHA-256; widest support, large signatures
PS256RSA-PSS with SHA-256; optional in RFC 7518
ES256ECDSA on P-256 with SHA-256; 64-byte signature
EdDSAEd25519 or Ed448 signatures from RFC 8037
noneNo signature; must never be accepted by default
These are PyJWT 2.15.1 calls we ran; other libraries have equivalents.
jwt.decode(t, key, algorithms=["RS256"])Pin the allowed algorithms; PyJWT refuses to decode if you leave the list out
jwt.decode(t, key, algorithms=["HS256"], audience="api://orders")Require the audience; a token with an aud claim fails when no audience is passed
issuer="https://auth.example.com"Reject tokens from any other issuer with InvalidIssuerError
leeway=60Allow 60 seconds of clock skew on exp and nbf
jwt.get_unverified_header(t)Read kid and alg before verifying, only to choose a key, never to trust content
typ: at+jwtCheck explicit typing so an ID token can't be replayed as an access token (RFC 9068)
Worked example: Watch a verifier reject bad tokens
We signed one HS256 token with PyJWT 2.15.1, then tried to verify it in different ways to see which checks actually fire.
secret = "k" * 32
tok = jwt.encode({"iss": "https://auth.example.com", "aud": "api://orders", "exp": 1}, secret, algorithm="HS256")
jwt.decode(tok, secret) # DecodeError: pass a value for "algorithms"
jwt.decode(tok, secret, algorithms=["HS256"]) # ExpiredSignatureError
opts = {"verify_exp": False}
jwt.decode(tok, secret, algorithms=["HS256"], options=opts) # InvalidAudienceError
jwt.decode(tok, secret, algorithms=["HS256"], options=opts,
audience="api://orders", issuer="https://evil.example") # InvalidIssuerError
Each failure is a guard rail doing its job. PyJWT will not guess the algorithm, so the classic RS256-to-HS256 swap needs a careless allow list to work. Expiry is checked before anything else. Because the token carries an aud, decoding without naming your audience fails rather than silently passing, and an issuer mismatch is caught even when everything else is right. We also built an alg: none token; decoding it with algorithms=["HS256"] raised InvalidAlgorithmError. One warning sign: a 5-byte HMAC key only produced a warning, not an error, so enforcing key length is your job.
Common mistakes
Trusting the
algvalue in the token headerConfigure the allowed algorithms on the verifier, one per key, so an attacker can't switch to none or to HS256 with your RSA public key.
Skipping the audience and issuer checks
Always pass the expected
audandiss. A token from the same identity provider minted for another app is otherwise accepted.Issuing access tokens that live for days
Keep access tokens short, minutes not days, and use refresh tokens. A JWT can't be revoked once issued without extra state.
Using a human password as the HS256 secret
Generate at least 32 random bytes. Low-entropy HMAC keys can be brute-forced offline from a single token.
Putting personal data in the payload
The payload is readable by anyone. Store an ID and look up the rest, or use JWE if the content must stay secret.
Related cheat sheets
Sources
- https://www.rfc-editor.org/rfc/rfc7519
- https://www.rfc-editor.org/rfc/rfc7515
- https://www.rfc-editor.org/rfc/rfc7518
- https://www.rfc-editor.org/rfc/rfc8037
- https://www.rfc-editor.org/rfc/rfc8725
- https://www.rfc-editor.org/rfc/rfc9068
- https://datatracker.ietf.org/doc/draft-ietf-oauth-rfc8725bis/
- https://pyjwt.readthedocs.io/en/stable/
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.