How to Decode JWT Tokens, Understand Base64URL Claims, and Verify HMAC Signatures
Inspect the 3-part RFC 7519 JSON Web Token structure, understand why Base64URL encoding is not encryption, verify HMAC-SHA256 signatures, and generate cryptographic secrets.
JSON Web Tokens (JWT) defined in IETF RFC 7519 are the industry standard for stateless API authentication, OAuth 2.0 access tokens, and OpenID Connect identity assertions. Yet one of the most dangerous misconceptions in web development is assuming that a signed JWT hides its contents from the client, or pasting live production bearer tokens into server-side debugging websites that log request payloads.
1. Anatomy of a Three-Part JWT (Header.Payload.Signature)
Every compact JWS (JSON Web Signature) token consists of three Base64URL-encoded segments separated by periods (.):
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfOTg0MiIsInJvbGUiOiJhZG1pbiIsImlhdCI6MTc5MjcxMzYwMCwiZXhwIjoxNzkyNzE3MjAwfQ.SignatureBytesHere
__________________________________/ __________________________________________________________________________________________/ ________________/
1. Header 2. Payload (Claims) 3. Signature
Part 1: The JOSE Header
Decoded from Base64URL, the header specifies the token type and the cryptographic signing algorithm:
{
"alg": "HS256",
"typ": "JWT"
}
Part 2: The Payload (Registered & Custom Claims)
The second segment contains the JSON claims asserting who the user is and when the token expires:
{
"sub": "usr_9842",
"role": "admin",
"iat": 1792713600,
"exp": 1792717200
}
| Registered Claim | Full Name (RFC 7519 §4.1) | Purpose & Validation Rule |
|---|---|---|
iss | Issuer | Identifies the auth server that issued the token |
sub | Subject | Unique user ID or principal identifier |
aud | Audience | Identifies the intended API or recipient service |
exp | Expiration Time | 10-digit Unix timestamp (seconds) after which the token must be rejected |
nbf | Not Before | Unix timestamp before which the token is not yet valid |
iat | Issued At | Unix timestamp when the token was minted |
jti | JWT ID | Unique identifier used to prevent token replay attacks |
You can inspect the decoded JSON header, payload claims, and live expiration countdown (exp / iat) 100% locally in your browser without transmitting your token over the network using the EverySolve JWT Token Decoder.
2. Encoding Is Not Encryption: Standard Base64 vs. Base64URL
A signed JWT (JWS) guarantees integrity and authenticity (nobody can tamper with "role": "user" to make it "role": "admin" without invalidating the signature), not confidentiality. Anyone who intercepts or inspects a JWT can decode its header and payload in milliseconds because they are simply encoded using Base64URL (RFC 4648 Section 5).
How does Base64URL differ from standard Base64 (RFC 4648 Section 4)?
- Standard Base64 uses
+(index 62),/(index 63), and=for padding—all three of which have special reserved meanings inside URLs and HTTP headers. - Base64URL replaces
+with-(hyphen), replaces/with_(underscore), and strips trailing=padding characters so the token can be safely passed in URLs, cookies, andAuthorization: Bearer <token>headers.
Never store plaintext passwords, credit card numbers, Aadhaar/SSN identifiers, or private API keys inside an unencrypted JWT payload. Test encoding and decoding raw UTF-8 strings and payloads with the EverySolve Base64 Encoder / Decoder.
3. How HS256 (HMAC-SHA256) Signatures Prevent Tampering
When the header specifies "alg": "HS256", the authentication server computes the third segment using a keyed Hash-based Message Authentication Code (HMAC-SHA256, RFC 2104) over the exact ASCII bytes of the first two segments joined by a dot:
Because an attacker does not possess the server's SecretKey, modifying even a single character in the payload produces a completely different 256-bit HMAC digest, causing the server's constant-time signature verification check to reject the request with 401 Unauthorized.
You can compute hexadecimal HMAC-SHA256, HMAC-SHA384, and HMAC-SHA512 digests for message strings and <Base64URL(Header)>.<Base64URL(Payload)> signing inputs directly in your browser using the EverySolve HMAC Signature Generator (note that compact JWTs encode those raw 32-byte HMAC digests as 43-character Base64URL strings without = padding).
4. Three Critical JWT Security Best Practices for Production
- Reject
"alg": "none"and Prevent RS256-to-HS256 Key Confusion: Early JWT libraries allowed attackers to set"alg": "none"in the header and strip the signature. An even subtler vulnerability is algorithm confusion: if a server expects an asymmetricRS256token (signed with a private RSA key and verified with a public RSA key) but does not enforce the algorithm, an attacker can change the header to"alg": "HS256"and sign the token symmetrically using the server's publicly available RSA public key bytes as the HMAC secret. Always pass an explicit whitelist of allowed algorithms (such as['HS256']or['RS256']) to your backend verification function. - Use High-Entropy Cryptographic Signing Secrets: If you sign tokens with
HS256using a weak dictionary word or short passphrase, an attacker can brute-force the secret offline using a single captured JWT because HMAC verification requires no network round-trip. IETF RFC 7518 Section 3.2 requires anHS256secret key to have at least 256 bits (32 bytes / 64 hex characters) of cryptographic entropy. Generate CSPRNG-backed 256-bit and 512-bit signing secrets locally with the EverySolve Secret Key & API Token Generator. - Keep Access Token Lifetimes Short (
exp): Because stateless JWTs cannot be revoked before they expire without maintaining a server-side denylist, keep access token lifetimes short (e.g., 15 to 60 minutes) and rotate refresh tokens securely.
For related cryptographic and payload validation workflows, read our guides on Generating Secure Passwords and Verifying Cryptographic Hashes and Validating JSON Schema Payloads.
Standards & Technical References
- RFC 7519 — JSON Web Token (JWT) — Internet Engineering Task Force (IETF) (Reference)
- RFC 2104 — HMAC: Keyed-Hashing for Message Authentication — Internet Engineering Task Force (IETF) (Reference)
- RFC 4648 — The Base16, Base32, and Base64 Data Encodings (Section 5: Base 64 Encoding with URL and Filename Safe Alphabet) — Internet Engineering Task Force (IETF) (Reference)
JWT token structure, registered claims, Base64URL alphabet, and HMAC-SHA256 message authentication verified against IETF RFC 7519, RFC 4648, and RFC 2104. EverySolve guides are written and maintained by our engineering and editorial team to document exact formulas, file-format standards, and browser-based workflows.
Frequently Asked Questions
Is it safe to paste a JWT into the EverySolve JWT Decoder?
Yes. The EverySolve JWT Decoder parses the Base64URL header and payload entirely inside your browser's local JavaScript memory using zero network requests. However, as a general security rule, you should still redact or rotate live production tokens before sharing decoded outputs in issue trackers.
Can a client decode a JWT without knowing the secret key?
Yes. The Header and Payload of a standard JWS token are merely Base64URL-encoded JSON, so anyone can read them without the secret key. The secret key is required only to verify that the token was not modified or to mint a new valid signature.
How long should an HS256 JWT signing secret be?
Under IETF RFC 7518 (JSON Web Algorithms), a key used with HMAC-SHA256 (HS256) must be at least 256 bits (32 bytes) long and generated using a cryptographically secure random number generator (CSPRNG) to prevent offline brute-force key recovery.
Related Online Tools
-
JWT Decoder & Inspector
Decode and view JSON Web Token headers, payload, and claims.
-
Base64 Encoder & Decoder
Encode text to Base64 or decode Base64 strings back to text.
-
HMAC Generator
Generate HMAC signatures (HMAC-SHA-256, SHA-384, SHA-512) locally in browser using Web Crypto API.
-
Secret Token Generator
Generate cryptographically secure API keys, secret tokens, and random hex/base64url strings using Web Crypto PRNG.
Related Guides & Tutorials
-
How to Generate High-Entropy Passwords and Cryptographic Hashes
Learn how password pool entropy is calculated, why Web Crypto CSPRNG matters, and the critical difference between SHA-256 checksums and password hashing.
-
How to Validate JSON Payloads Against JSON Schema Specifications
Prevent runtime API bugs by validating incoming JSON structures, required keys, data types, and regex patterns against a formal JSON Schema contract.
-
How to Format, Pretty-Print, and Debug Broken JSON Data
Turn unreadable single-line API payloads into indented JSON trees, minify payloads for production transit, and fix the 5 most common RFC 8259 syntax errors.