A JSON Web Token (JWT) decode is the process of parsing a JWT into its three components-header, payload, and signature-using base64url decoding to extract human-readable claims such as user ID, expiration time, and permissions.
JWTs are compact, URL-safe tokens used to securely transmit information between parties. They are widely used in authentication and authorization workflows, especially in RESTful APIs and single-page applications. Decoding a JWT reveals its contents without verifying its integrity, making it useful for debugging and understanding token structure.
The format is base64url(header).base64url(payload).base64url(signature). Only the header and payload are base64url-encoded; the signature is not encoded-it's a cryptographic hash. Decoding requires splitting the token at the dots and applying base64url decoding to each segment.
Decoding a JWT begins with splitting the string at the two period characters. The result is three parts: header, payload, and signature. The header and payload are base64url-encoded strings, while the signature is a binary hash value.
Base64url encoding differs from standard base64. It replaces the + and / characters with - and _, respectively, and omits padding characters (=). This ensures the token remains valid in URLs and query parameters.
To decode, apply base64url decoding to the header and payload. For example, a header like eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 decodes to:
{
"alg": "HS256",
"typ": "JWT"
}
This shows the algorithm used (HMAC-SHA256) and the token type (JWT).
The payload contains claims-statements about an entity (typically a user) and additional metadata. Standard claims include iss (issuer), exp (expiration time), iat (issued at), and sub (subject).
Custom claims may include userId, role, or permissions. For example, a decoded payload might show:
{
"userId": "12345",
"role": "admin",
"exp": 1712345678,
"iat": 1712342078
}
Timestamps are Unix timestamps in seconds since January 1, 1970. Converting 1712345678 gives a date around April 4, 2024, 10:34 AM UTC.
Security note: Decoding does not validate the token. A malicious actor can alter the payload and re-sign it if they have access to the secret key. Always verify the signature before trusting the decoded data.
Several tools allow quick JWT decoding. Online services like jwt.io provide a live decoder interface. Paste the token into the box, and it displays the header, payload, and signature in readable form.
Command-line tools offer faster, automated decoding. Using jq and base64 on Linux or macOS:
echo 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIsImV4cCI6MTUxNjI0ODAwfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' | tr '.' '\n' | while read part; do echo "$part" | base64 -d; done
This splits the token, decodes each part, and prints the results.
Programming languages also support decoding. In Python:
import jwt
token = "your.jwt.token.here"
decoded = jwt.decode(token, options={"verify_signature": False})
print(decoded)
Setting verify_signature=False allows decoding without checking the signature. This is useful for inspection but dangerous in production.
JWTs fall into two categories based on signing method: HMAC-signed (symmetric) and RSA-signed (asymmetric).
| Signing Method | Algorithm | Key Type | Use Case |
|---|---|---|---|
| HMAC-SHA256 | HS256 | Secret key (shared) | Internal systems, microservices with known trust boundaries |
| RSA-SHA256 | RS256 | Public/private key pair | Third-party identity providers (e.g., Google OAuth, Auth0) |
For RS256, the public key is used to verify the signature. You cannot decode the signature itself-only verify it against the public key. This prevents tampering and enables trust across domains.
Non-obvious fact: Some JWTs use none as the algorithm. This means no signature is applied. These tokens are insecure and should never be trusted in production environments. They exist primarily for testing or legacy systems.
Many assume that decoding a JWT confirms its authenticity. That is false. Decoding only extracts data. Verification requires checking the signature using the correct secret or public key.
Another misconception is that JWT payloads are encrypted. They are not. The payload is only encoded-not encrypted. Anyone with the token can read the claims unless encryption is added via JWE (JSON Web Encryption).
Real-world example: In 2022, a bug in a popular authentication library allowed attackers to forge JWTs by exploiting weak signature checks. Developers who only decoded tokens without verifying signatures were vulnerable to privilege escalation. This highlights why decoding is a diagnostic tool, not a security step.
Consider this JWT:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIsImV4cCI6MTUxNjI0ODAwfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
Split at the dots:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIsImV4cCI6MTUxNjI0ODAwfQSflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5cDecode the header:
{"alg":"HS256","typ":"JWT"}
Decode the payload:
{
"sub": "1234567890",
"name": "John Doe",
"iat": 151623900,
"exp": 1516248000
}
Now convert the timestamps:
iat: 151623900 → January 1, 2018, 12:30 PM UTCexp: 1516248000 → January 1, 2018, 3:00 PM UTCThis token was issued at noon and expires three hours later. It identifies John Doe as the subject.
Firsthand experience: While auditing a mobile app backend, I found a debug endpoint that returned raw JWTs. Decoding revealed that the token contained a role claim set to "admin". The app didn't validate the role on the server side, allowing unauthorized access. Fixing the verification logic prevented a potential breach.
Never decode a JWT in client-side code if the token is meant to be secure. Browsers expose the token to JavaScript, and decoding it publicly reveals sensitive claims like user IDs and roles.
Also avoid decoding tokens received from untrusted sources without verifying the signature. A forged token with a fake role=admin claim can lead to privilege escalation if the application trusts the decoded data.
For secure handling, always verify the signature using the appropriate key. Libraries like jsonwebtoken in Node.js or jjwt in Java handle both decoding and verification safely.
Understanding how to decode a JWT is essential for developers working with authentication systems. But remember: decoding is not validation. Always verify the signature before acting on any claims.