JWTs show up in almost every modern login system. Here's what the three parts actually mean, and what a JWT can't do for you.
If you've ever opened your browser's dev tools and seen a long string starting with "eyJ" sitting in local storage or a cookie, you've seen a JWT. They're everywhere in modern web authentication, and the name — JSON Web Token — is at least honest about what's inside: JSON data, formatted for the web. Understanding the structure demystifies a lot of what's actually happening every time you log into something.
A JWT is three sections separated by periods: header.payload.signature. Each of the first two sections is a JSON object that's been Base64URL-encoded into a compact string of letters and numbers — not encrypted, just encoded, which is an important distinction covered below. The header describes the token itself: typically which algorithm was used to sign it. The payload is the actual data the token is carrying — commonly a user ID, an expiration timestamp, and whatever other claims the application decided to include. The signature is a cryptographic hash of the header and payload, created using a secret key that only the server knows, and it's what makes the token tamper-proof.
This is the single most common misunderstanding about JWTs: the header and payload are encoded, not encrypted. Anyone — not just the server — can decode a JWT and read exactly what's inside it, including a browser extension, a curious user, or anyone the token gets shared with. What they can't do is modify the payload and produce a new, valid signature, because generating a correct signature requires the server's secret key, which never leaves the server. That's the actual security model: JWTs aren't private, they're tamper-evident. Never put a password, a credit card number, or anything genuinely secret directly in a JWT payload.
If you're debugging "why is my API returning 401 Unauthorized," decoding your JWT and checking the `exp` (expiration) claim against the current time catches a surprising number of auth bugs — tokens expire more often than people expect during development.
Before JWTs were common, a lot of web apps used server-side sessions: the server stores your login state in memory or a database, and gives your browser a short session ID cookie that points back to it. JWTs flip that around — the token itself carries the data, so the server doesn't need to look anything up to verify who you are, just check the signature. That statelessness makes JWTs convenient for APIs and services running across multiple servers, since any of them can verify a token independently without sharing a session database.
Because a JWT is self-contained, revoking one before its natural expiration is awkward — there's no built-in "delete this session" the way there is with a server-side session store, since the server isn't tracking which tokens exist. Most real systems work around this with short expiration times plus a refresh-token mechanism, or by maintaining a denylist of revoked tokens, which reintroduces some of the server-side bookkeeping JWTs were meant to avoid. It's a genuine trade-off, not a free upgrade over sessions.
Decode a JWT's header and payload, with expiry and issued-at times.
Encode text to Base64 or decode Base64 back to text, with correct UTF-8 handling.
Pretty-print, minify, and validate JSON with clear error locations.
No — anyone can construct a JWT-shaped string with arbitrary payload data. The signature is what confirms the token was actually issued by the server and hasn't been tampered with.
That's the Base64URL encoding of the opening characters of a JSON object (`{"`) — since every JWT header starts with a JSON object, they all begin with the same encoded prefix.
Not exactly — OAuth is an authorization framework, and JWT is just a token format. Many OAuth implementations use JWTs as the token format, but OAuth can also issue opaque (non-JWT) tokens.
The last part of a URL does more SEO and usability work than its size suggests. Here's how to write one well.
Regular expressions are powerful and famously unreadable. Here's how to build one up piece by piece instead of guessing blindly.
Spaces, symbols, and special characters can't travel safely in a URL as-is. Here's the actual rule for what gets encoded and why.
That 36-character string of hex digits and dashes shows up in database records, API responses, and file names everywhere. Here's why.