Cryptology Academy · Lesson

JWT Anatomy: Header, Payload, Signature

Decode base64url parts and understand each JWT field.

Lesson 1 of 413 steps

JWT Anatomy: Header, Payload, Signature is a free Cryptology Academy lesson on CoddyKit. This is lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, and your progress syncs across the web and the CoddyKit app. The Cryptology Academy course includes 4 lessons in total.

What Is a JWT?

A JSON Web Token (JWT) is a compact, URL-safe token format defined in RFC 7519. It encodes claims (assertions about a subject) and a cryptographic signature in a single string, enabling stateless authentication.

Three-Part Structure

A JWT has the form: base64url(header).base64url(payload).base64url(signature). The dot separates the parts. The header and payload are readable (base64url, not encrypted). Only the signature is cryptographic.

Header

The header is a JSON object: {"alg":"HS256","typ":"JWT"}. alg specifies the signing algorithm (HS256, RS256, ES256, none). typ is always "JWT". Additional headers include kid (key ID) for key selection.

Payload / Claims

Standard registered claims: iss (issuer), sub (subject), aud (audience), exp (expiry Unix timestamp), nbf (not before), iat (issued at), jti (JWT ID for revocation). Custom claims are any additional key-value pairs.

Decoding a JWT

import base64, json token = "eyJ..." parts = token.split(".") header = json.loads(base64.urlsafe_b64decode(parts[0]+"==")) payload = json.loads(base64.urlsafe_b64decode(parts[1]+"==")) print(header, payload)

Signature Verification

For HS256: HMAC-SHA256(base64url(header)+"."+base64url(payload), secret). The receiver recomputes this and compares to the signature part. If they match and the token is not expired, the token is valid.

Asymmetric Signatures

For RS256: the private key signs the header.payload string using RSA-SHA256. Any party with the public key can verify without the private key. Public keys are distributed via JWKS (JSON Web Key Set) endpoints (e.g., /.well-known/jwks.json).

Base64url Encoding

Base64url replaces + with - and / with _, and omits = padding. This makes JWTs safe in URLs, HTTP headers, and cookies without percent-encoding. The raw bytes are still not encrypted — just encoded.

JWTs Are Not Encrypted By Default

A JWT payload is visible to anyone who base64url-decodes it. Never put secrets (passwords, SSNs) in a JWT payload unless you use JWE (JSON Web Encryption) with the "enc" algorithm for actual encryption.

Token Lifetime

Set exp to a short duration (15-60 minutes for access tokens). Long-lived JWTs accumulate risk — if stolen, they remain valid until expiry. Use refresh tokens (stored securely) to issue new short-lived access tokens.

JWKS Discovery

Auth providers (Auth0, Keycloak, Google) publish a JWKS URL. The verifier fetches public keys by kid, caches them, and verifies signatures without contacting the issuer per-request. Key rotation updates the JWKS endpoint.

Quick Check

Which part of a JWT contains the cryptographic signature?

Recap

A JWT is three base64url-encoded JSON parts: header (algorithm), payload (claims), and signature. The payload is readable — not encrypted. Next: choosing between HS256 and RS256.

Free to start

Learn Cryptology Academy with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
67
Lessons
261

Frequently Asked Questions

Is the “JWT Anatomy: Header, Payload, Signature” lesson free?

Yes — the full text of “JWT Anatomy: Header, Payload, Signature” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO. The Cryptology Academy course includes 4 lessons in total.

What will I learn in “JWT Anatomy: Header, Payload, Signature”?

Decode base64url parts and understand each JWT field. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cryptology Academy?

No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.

How long does the “JWT Anatomy: Header, Payload, Signature” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cryptology Academy lesson?

Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. JWT Anatomy: Header, Payload, Signature
  2. HS256 vs RS256: Symmetric vs Asymmetric JWTs
  3. JWT Vulnerabilities: alg=none & Key Confusion
  4. Secure JWT Implementation Best Practices
← Back to Cryptology Academy