## A JWT Is Three Base64 Chunks
A JSON Web Token looks like this:
text eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ik5vdmVsQ3J5cHQgVXNlciIsImlhdCI6MTczNTY4OTYwMH0.sVwR3q3qX9Xb2kP0mN4lH6jK8oYtZ1aBcDfGhIjKlM
Three parts, separated by dots. The first is the header. The second is the payload. The third is the signature. The first two are Base64url-encoded JSON. The third is a signature and you do not decode it — you verify it.
This matters because it means you can read a JWT with nothing but a Base64 decoder. No JWT library. No auth SDK. No network call. If you can decode Base64, you can inspect any JWT that crosses your desk. That is useful for debugging, for understanding what your auth system is doing, and for spotting tampered tokens.
Decode the JWT Base64 Header
Take the first chunk and decode it. Remember from URL-safe Base64 that JWTs use Base64url, so - and _ replace + and /, and padding is omitted.
javascript function decodeJwtPart(part) { const pad = part + "=".repeat((4 - (part.length % 4)) % 4); const b64 = pad.replace(/-/g, "+").replace(/_/g, "/"); return JSON.parse(atob(b64)); }
const header = decodeJwtPart("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"); // { "alg": "HS256", "typ": "JWT" }
The header tells you the signing algorithm and the token type. That is it. But it is the first thing to check — if alg is none in a production token, something is wrong. Some libraries historically accepted none as a valid algorithm, which means a token with no signature was treated as valid. That is an attack vector. Reject it.
Inspect the JWT Payload
The second chunk is the one you usually care about. It holds the claims:
javascript const payload = decodeJwtPart( "eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ik5vdmVsQ3J5cHQgVXNlciIsImlhdCI6MTczNTY4OTYwMH0" ); // { // "sub": "1234567890", // "name": "NovelCrypt User", // "iat": 1735689600 // }
sub is the subject (usually the user ID). iat is "issued at" as a Unix timestamp. exp is the expiry. role or scope may carry permissions. This is the data your server uses to authorize the request. Reading it by hand tells you exactly what the token claims, without trusting a library to interpret it for you.
The Signature Is Not for Decoding
The third chunk is an HMAC or RSA signature over the first two chunks. You do not Base64-decode it to read it. You verify it with the signing secret or public key. If the signature does not match, the header or payload has been tampered with.
This is the critical distinction: anyone can decode the payload. Base64 is reversible by design. Only someone with the secret can verify the signature. A JWT is not encrypted — it is signed. For the difference, read Base64 is not encryption.
A Real Debugging Session
A user reports "I keep getting logged out." You grab their token from the request header:
text Authorization: Bearer eyJhbGciOi...
Decode the payload. Check exp. It is 1735689600. Convert it: that is midnight on the first day of 2025. The token expired months ago. The bug is not in your auth logic — it is a stale token in the client. Five seconds of Base64 decoding saved an hour of log diving.
Another scenario: a user reports "I get a 403 on every request." Decode the payload. Check role. It says guest. The user thinks they are an admin, but the token says otherwise. The bug is in the login flow that issued the wrong role. Again, decoding the payload by hand pointed you straight at the problem.
Common JWT Pitfalls
**alg: none.** A token with no signature is a known attack vector if your library accepts it. Reject it. Some libraries have been vulnerable to this in the past. Always check the algorithm in the header against a list you control.
**Trusting the payload.** Anyone can decode a JWT. Anyone can encode a fake one. The payload is only trustworthy after the signature verifies. Never authorize on decoded-but-unverified claims. This is the most dangerous JWT mistake.
**Base64 vs Base64url.** JWTs use Base64url. If you decode a JWT chunk with standard atob and the chunk contains a - or _, you get garbage. Always swap the alphabet first. This is the most common decoding error.
**Missing padding.** JWT chunks are usually unpadded. Re-add = before decoding or your decoder will fail on chunks whose length is not a multiple of 4. The decodeJwtPart function above handles this.
**Expiry not checked.** A valid signature on an expired token is still expired. Always check exp after verifying the signature. A token that was valid yesterday is not valid today, even if the signature still matches.
A One-Function JWT Inspector
javascript function inspectJwt(token) { const [header, payload] = token.split("."); return { header: decodeJwtPart(header), payload: decodeJwtPart(payload), signature: "(verify with the signing key)" }; }
inspectJwt(yourToken); // { header: {...}, payload: {...}, signature: "..." }
No library. No network call. Just Base64 and JSON.parse. Paste a token into the NovelCrypt Base64 encoder and you can do the same thing by hand. The encoder handles the Base64url alphabet swap and padding for you, so it is a quick way to inspect a token without writing any code.
Quick Reference
- A JWT is header.payload.signature, all Base64url-encoded. - Decode header and payload with Base64url + JSON.parse. - Do not decode the signature — verify it with the signing key. - Always check exp after verifying the signature. - Never trust claims from an unverified token.
For the Base64url format that JWTs depend on, see URL-safe Base64 encoding.,