How to jwt decode
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 4, 2026
Key Facts
- A JWT is composed of three parts separated by dots: Header.Payload.Signature.
- The header and payload are base64url encoded JSON objects.
- Decoding the header and payload reveals their JSON structure.
- The signature is used to verify the token's integrity and authenticity.
- JWTs are commonly used for authentication and information exchange in web applications.
What is a JWT?
A JSON Web Token (JWT) is a compact, URL-safe means of representing claims to be transferred between two parties. It is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs are commonly used for authentication and information exchange in web applications, particularly in APIs and single sign-on (SSO) systems. They allow a server to communicate information about a user or an application to another party without needing to be re-queried.
Understanding JWT Structure
A JWT consists of three parts, separated by dots (.):
- Header: This part contains metadata about the token, such as the type of token (JWT) and the signing algorithm being used (e.g., HMAC SHA256 or RSA). The header is itself a JSON object and is base64url encoded.
- Payload: This part contains the claims. Claims are statements about an entity (typically, the user) and additional data. Common claims include user ID, roles, expiration time, issuer, and audience. Like the header, the payload is a JSON object and is base64url encoded.
- Signature: This part is used to verify that the sender of the JWT is who it says it is and to ensure that the message wasn't changed along the way. It is created by taking the encoded header, the encoded payload, a secret (for symmetric algorithms) or a private key (for asymmetric algorithms), and signing them using the algorithm specified in the header.
How to Decode a JWT
Decoding a JWT involves separating its three components and then decoding the header and payload. The signature is not decoded in the same way; it's used for verification.
Step 1: Split the Token
The first step is to split the JWT string by the dot (.) character. This will give you three parts: the encoded header, the encoded payload, and the encoded signature.
Step 2: Decode the Header
The header is base64url encoded. You can use any base64url decoding tool or library available in your programming language to decode this part. Once decoded, you will get a JSON string representing the header object. You can then parse this JSON string to access its contents.
Step 3: Decode the Payload
Similarly, the payload is also base64url encoded. Decode this part using a base64url decoder. The result will be a JSON string containing the claims. Parse this JSON string to read the claims, such as user ID, roles, and expiration dates.
Step 4: Verify the Signature (Crucial for Security)
While you can decode the header and payload to read their contents, you should never trust the data from a JWT without verifying its signature. The signature verification process ensures that the token has not been tampered with and was indeed issued by the expected party. This process involves:
- Retrieving the header and payload.
- Using the algorithm specified in the header.
- Using the secret or public key associated with the issuer.
- Re-creating the signature using the same process as the issuer.
- Comparing the newly generated signature with the signature provided in the token. If they match, the token is valid.
Important Security Note: Decoding the header and payload is straightforward and can be done by anyone. However, the security of JWTs relies entirely on the signature verification. Always verify the signature using the correct secret or public key before trusting the claims within the payload. Failure to do so can lead to serious security vulnerabilities, allowing attackers to forge tokens and gain unauthorized access.
Tools and Libraries for JWT Decoding
There are numerous tools and libraries available to help you decode and verify JWTs:
- Online JWT Decoders: Websites like jwt.io allow you to paste a JWT and see its decoded header and payload. These are excellent for quick inspection but should not be used for sensitive tokens or verification.
- Programming Language Libraries: Most popular programming languages have robust JWT libraries (e.g.,
python-jwtfor Python,jsonwebtokenfor Node.js,java-jwtfor Java). These libraries handle both decoding and secure signature verification.
When using libraries, you typically provide the JWT string and the secret or public key to a verification function. The library will then decode the token, verify the signature, and return the claims if the token is valid, or throw an error if it's invalid.
When to Decode a JWT
You might need to decode a JWT in several scenarios:
- Debugging: To inspect the contents of a token during development to ensure the correct claims are being issued.
- Auditing: To examine tokens for security or compliance purposes.
- Client-Side Rendering: To extract user information (like user ID or roles) from a token stored on the client (e.g., in local storage or cookies) to personalize the user interface. However, remember that client-side data can be manipulated, so critical authorization decisions should always be made on the server after signature verification.
In summary, decoding a JWT involves base64url decoding the header and payload components to reveal their JSON structure. However, the critical step for security is always to verify the token's signature using the appropriate secret or public key.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- JSON Web Tokensfair-use
- RFC 7519: JSON Web Token (JWT)CC0-1.0
Missing an answer?
Suggest a question and we'll generate an answer for it.