Decode JWT Tokens Locally: Safe Method
In this article
Yes, you can safely decode JWT tokens locally in your browser or on your own machine without any backend server. The JSON Web Token format is designed to be publicly readable—the header and payload are only Base64Url-encoded, not encrypted—so decoding them is a purely local, offline operation that exposes no secrets and requires no network requests.
What a JWT Actually Contains
A JWT is a compact, URL-safe string with three parts separated by dots: header.payload.signature. The header typically specifies the signing algorithm (like HS256 or RS256) and the token type. The payload carries the claims—statements about the user or session, such as sub (subject), exp (expiration), iat (issued at), and custom fields like role or email. The signature is a cryptographic hash of the header and payload combined with a secret key (for HMAC algorithms) or a private key (for RSA/ECDSA).
Critically, the header and payload are not encrypted. They are encoded using Base64Url, which is just a reversible encoding scheme. Anyone who intercepts a token can read its contents without any key. The signature is what prevents tampering—if you modify the payload, the signature no longer matches, and a server verifying the token will reject it.
Why Local Decoding Is Safe
Decoding a JWT locally is safe because you are only reversing the Base64Url encoding on the first two segments. You are not verifying the signature (which would require the secret key) and you are not sending the token anywhere. The operation is equivalent to reading a plain-text JSON file. The token itself is already visible to anyone who has it, so decoding it on your own device adds no additional exposure.
The only risk would be if you pasted a token into an online decoder that sends it to a remote server—that would leak the token to a third party. A local method avoids that entirely. You can use a browser's developer console, a command-line tool, or a small script, all of which keep the token on your machine.
How to Decode Manually (Step by Step)
Here is a manual method using only a browser's developer tools (no extensions needed):
- Open the browser's developer console (F12 or right-click → Inspect → Console).
- Copy the JWT string (it looks like
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0In0.sflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c). - In the console, run:
atob(token.split('.')[1])to decode the payload. Use[0]for the header. - Wrap the result in
JSON.parse(atob(token.split('.')[1]))to get a readable object. - If the payload contains URL-safe characters (like
-or_), replace them first:atob(token.split('.')[1].replace(/-/g,'+').replace(/_/g,'/')).
This works because atob() decodes Base64, and the JWT payload is just Base64Url. The same process applies to the header. The signature (third part) is not decodable—it is binary data, not JSON.
Using a Local Script or Tool
If you need to decode many tokens or want a more reusable method, you can write a tiny script. In Node.js, for example:
const token = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0In0.sflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64url').toString());
console.log(payload);
Alternatively, you can use a command-line tool like jq with a base64 decode step, or a desktop app that runs entirely offline. The key is that the tool must not send the token over the network. Any tool that says “decode locally” or “offline” is fine.
Common Misconceptions and Pitfalls
- “Decoding is the same as verifying.” No. Decoding just reveals the contents. Verification checks the signature to ensure the token hasn't been altered. You cannot verify an HMAC token without the secret key, and you cannot verify an RSA token without the public key. Local decoding does not verify anything.
- “The payload is encrypted.” It is not. It is only encoded. Anyone can read it. Do not put sensitive data (like passwords) in a JWT payload.
- “Base64Url is the same as Base64.” Almost, but not exactly. Base64Url uses
-and_instead of+and/, and omits padding=. When decoding, you may need to convert. - “The signature can be decoded too.” The signature is raw bytes, not JSON. It cannot be read as text. It is meant to be checked, not read.
When You Should Not Decode Locally
Local decoding is only useful for inspecting the token's claims. It is not appropriate for:
- Verifying authenticity—you need the server's secret key (HMAC) or public key (RSA/ECDSA) and a proper verification library.
- Checking expiration—you can read the
expclaim, but you cannot trust it unless the signature is verified. - Debugging server-side issues—if a token is rejected, local decoding won't tell you why; you need to check the server logs.
For verification, use a library like jsonwebtoken in Node.js or PyJWT in Python, which handle both decoding and signature checking.
Frequently Asked Questions
Is it safe to paste a JWT into an online decoder?
Technically, the token is already exposed to anyone who intercepts it, but pasting it into an online service sends it to a third party's server, which could log or misuse it. For production tokens, avoid online decoders. Use a local method instead.
Can I decode a JWT without knowing the secret key?
Yes, for the header and payload. The secret key is only needed to create or verify the signature. Decoding the first two parts requires no key.
What does the signature part of a JWT look like when decoded?
It is binary data, not text. It will appear as random characters or bytes. You cannot read it as JSON; it is meant to be compared against a computed signature.
Is a JWT the same as a session token?
No. A session token is often an opaque random string stored on the server. A JWT is self-contained—it carries its own claims. But both can be used for authentication.
Can I decode a JWT in Python?
Yes. Use base64.urlsafe_b64decode after adding padding, or use a library like PyJWT which can decode without verifying if you pass options={"verify_signature": False}.
Does decoding a JWT invalidate it?
No. Decoding is a read-only operation. It does not change the token or affect its validity. The token remains valid until it expires or is revoked by the server.