# How JWT Signing Works: Claims, HS256 Secrets, and Safe Decoding

> Understand header, payload claims (iss, sub, exp, iat), HMAC-SHA256 signatures, and why JWT payloads are Base64Url encoded — never encrypted.

- URL: https://proit.tools/guides/how-to-sign-and-verify-jwt-tokens-safely
- Author: Mohammed Zawwar Hussain
- Published: 2026-12-01
- Updated: 2026-12-01
- Publisher: ProIT (proit.tools)

## Anatomy of a JSON Web Token: Header, Payload, and Signature

Every compact JWS JSON Web Token consists of three dot-separated ASCII segments: `header.payload.signature`. First, the **Header** declares metadata such as signing algorithm (`"alg": "HS256"` or `"RS256"`) and token type (`"typ": "JWT"`). Second, the **Payload** holds JSON claim pairs identifying user identity, roles, issuer, and timestamps. Third, the **Signature** binds the Base64Url-encoded header and payload cryptographically using your server secret key or asymmetric private key so tampered tokens reject cleanly upon verification.

        Signing Input = base64url(JSON_Header) + "." + base64url(JSON_Payload)
HS256 Signature = base64url(HMAC_SHA256(Signing_Input, Secret_Key))
        **Crucial security principle every engineer must enforce:** Standard signed JWTs (JWS) are *encoded* with Base64Url, **never encrypted**. Anyone capturing an HTTP Bearer header can decode the middle payload segment cleanly in one second—so never store database passwords, credit card numbers, raw internal API keys, or sensitive health identifiers inside JWT claims.

## Standard registered JWT claims and time-window debugging

| Claim Key | Meaning | Format / Developer Gotcha |

| `sub` | Subject (user ID / UUID) | Prefer opaque internal IDs rather than mutable email strings |

| `iss` / `aud` | Issuer & Audience | Always validate both on API servers so tokens from other apps are rejected |

| `exp` / `iat` / `nbf` | Expiration, Issued At, Not Before | Always whole Unix epoch SECONDS (10 digits), never JS milliseconds (13 digits)! |

        Accidentally setting `exp: Date.now() + 3600000` in Node.js or frontend prototypes—instead of `Math.floor(Date.now() / 1000) + 3600`—writes millisecond timestamps interpreted by RFC 7519 libraries as expiring around the year 54,000 AD! Verify human-readable UTC/local expiry cleanly via [JWT Token Inspector](https://proit.tools/tool/jwt-decoder) and [Unix Timestamp Converter](https://proit.tools/tool/unix-timestamp-converter).

## Constructing, signing, and verifying test tokens inside your browser

- **Generate crisp test secrets safely:** Avoid weak staging keys like `secret123` that leak into brute-force dictionaries or accidentally ship to production. Create 256-bit+ random test secrets via [Strong Password Generator](https://proit.tools/tool/strong-password-generator).

- **Build and sign HS256 test payloads locally:** Open [JWT Token Builder & Signer](https://proit.tools/tool/jwt-builder), edit custom JSON claims cleanly (including `exp` and role scopes), paste your test HMAC secret, and sign locally using native Web Crypto HMAC-SHA256—zero tokens or test secrets leave your browser.

- **Inspect production Bearer strings safely:** Never paste live user authentication tokens into random remote decoder APIs that log request payloads. Use [JWT Token Inspector](https://proit.tools/tool/jwt-decoder), which decodes Base64Url headers and claims strictly client-side in your browser and flags expired timestamps immediately.

- **Cross-check raw HMAC webhook digests:** Debugging custom API webhooks alongside JWT auth? Test identical raw key-and-message SHA-256 HMAC digests cleanly via [HMAC Signature Generator](https://proit.tools/tool/hmac-generator).

## Four critical JWT production pitfalls (alg=none, secret strength & revocation)

First, always pin expected algorithms explicitly in your backend verification call (e.g. `algorithms: ['HS256']`) so attackers cannot trick misconfigured libraries with `"alg": "none"` or key-confusion RS256-to-HS256 downgrades. Second, keep access token lifetimes short (5–15 minutes) paired with revocable refresh sessions so logged-out or password-reset users lose access rapidly rather than holding valid stateless tokens for weeks. Third, sanitize decoded claim fields before storing or logging, and keep tokens out of URL query strings where server access logs and browser history expose Bearer credentials.

## Worked debugging walkthrough: diagnosing 401 Unauthorized API errors

When a mobile app or React frontend hits sudden `401 Unauthorized` responses from staging APIs, resist guessing backend deployment glitches before inspecting the live Bearer token directly inside [JWT Token Inspector](https://proit.tools/tool/jwt-decoder). Paste the full dot-separated string from DevTools Network headers without trailing spaces and inspect four checks immediately: (1) confirm `exp` decoded to UTC time has not expired due to container clock drift, (2) verify `iss` and `aud` strings match the exact target environment URL rather than old localhost settings, (3) confirm user role scopes carry required permissions, and (4) generate a clean test token with [JWT Token Builder & Signer](https://proit.tools/tool/jwt-builder) using an identical trimmed UTF-8 HMAC secret to separate frontend stale-cookie caching from backend key mismatches in under two minutes.

## Related tools

- [JWT Token Builder](https://proit.tools/tool/jwt-builder): Construct and sign test HS256 JWT tokens in browser
- [JWT Token Inspector](https://proit.tools/tool/jwt-decoder): Inspect header, claims, and human-readable expiry locally
- [HMAC Signature Generator](https://proit.tools/tool/hmac-generator): Verify keyed SHA-256 webhook and token signatures

## Frequently asked questions

### Are my production Bearer JWT tokens sent to a server when decoded?

No. JWT Token Inspector and JWT Token Builder execute purely inside your browser without transmitting tokens or secrets.

### Is data inside a JWT payload hidden or encrypted from users?

No. Standard signed JWTs are Base64Url encoded—anyone holding the token can decode and read header and payload JSON without knowing the signing secret.

### Why did my JWT library say a freshly signed token stays valid for 50,000 years?

RFC 7519 exp and iat timestamps expect 10-digit Unix seconds, not 13-digit JavaScript milliseconds from Date.now().

### Can JWT Token Builder sign RS256 private-key tokens too?

JWT Token Builder constructs and signs HS256 (HMAC-SHA256) tokens cleanly using shared test secrets right inside browser Web Crypto.

### What causes Signature Invalid when my payload looks identical?

Even one extra whitespace byte, JSON key reordering, or mismatch between trimmed vs newline-padded HMAC secrets alters the Base64Url string and breaks HMAC verification immediately.

### How long should production access JWT lifetimes be?

Keep signed access tokens short-lived (between 5 and 15 minutes) paired with rotatable server-validated refresh tokens so compromised devices lose API access quickly after logout or password resets.

