Skip to content

Menu

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.

Verifying a JWTThe verifier, not the token header, decides the algorithm and the key; then issuer, audience, time and type checks decide whether the claims can be used.Token arrivesheader.payload.signature, base64url partsalg is on your allowed liste.g. algorithms=["RS256"]none, or HS256 with your RSA key → rejectPick the keykid names a key in your JWKSjku / x5u: never fetch blindlySignature verifiesrejectissexact matchaudthis serviceexp / nbfsmall leewaytyp: at+jwtID token can't pass as access tokenUse the claims
The verifier, not the token header, decides the algorithm and the key; then issuer, audience, time and type checks decide whether the claims can be used.

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.signature

Compact JWS form: three base64url parts joined by dots

{"alg":"HS256","typ":"JWT"}

Typical header; alg is required and must be understood by the verifier

kid

Header hint naming which key signed the token, used to pick a key from a JWKS

From the docs, not run by us
jku / x5u

Header URLs pointing at keys or certs; never fetch them blindly, they are an SSRF and key-injection risk

From the docs, not run by us
crit

Header listing extensions the verifier must understand or reject the token

From the docs, not run by us
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.

iss

Issuer; compare it exactly against the issuer you trust

sub

Subject, usually a user ID unique within the issuer

aud

Audience, a string or array; a service not listed must reject the token

exp

Expiry time; reject when now is at or after it, allowing a few minutes of clock skew at most

nbf

Not-before time; reject tokens used too early

Try it: JWT Claims BuilderFrom the docs, not run by us
iat

Issued-at time, used to work out the token's age

jti

Unique token ID, for replay detection or a deny list

Try it: JWT Claims BuilderFrom the docs, not run by us

EdDSA is defined in RFC 8037 (https://www.rfc-editor.org/rfc/rfc8037). RFC 7518 requires RSA keys of 2048 bits or more.

HS256

HMAC with SHA-256 and a shared secret of at least 32 bytes; the only algorithm RFC 7518 makes required

RS256

RSA PKCS#1 v1.5 signature with SHA-256; widest support, large signatures

Try it: JWT GeneratorFrom the docs, not run by us
PS256

RSA-PSS with SHA-256; optional in RFC 7518

From the docs, not run by us
ES256

ECDSA on P-256 with SHA-256; 64-byte signature

EdDSA

Ed25519 or Ed448 signatures from RFC 8037

none

No 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=60

Allow 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+jwt

Check explicit typing so an ID token can't be replayed as an access token (RFC 9068)

From the docs, not run by us

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 alg value in the token header

    Configure 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 aud and iss. 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.