sub (Subject) Claim in a JWT
sub identifies the principal the token is about, usually the end user. It is unique within the issuer, not globally, so the reliable key for an account is the iss and sub pair together.
At a glance
- Claim
- sub (Subject)
- Defined in
- RFC 7519 section 4.1.2
- Value type
- StringOrURI, case sensitive
- Required
- Optional in RFC 7519. Required in an OpenID Connect ID token, where it is capped at 255 ASCII characters.
- Sample value
- 8f14e45fceea167a5a36dedd4bea2543
- In the decoder
- Explained by name, listed under Registered claims as Subject. A token with no sub gets an informational note.
In detail
RFC 7519 says the subject value must be locally unique in the context of the issuer, or globally unique. That word locally is the whole story: an issuer promises the identifier is stable and unambiguous inside its own directory and promises nothing outside it. OpenID Connect adds that the value must never be reassigned to a different person, which is the property that lets you use it as an account key.
Identity providers issue two shapes of subject. A public subject is the same string for every application connected to that provider. A pairwise subject is derived per client, so the same human appears as a different sub to each application, which stops two relying parties from correlating their user lists. Switching an application between the two, or moving it to a new client registration, changes every sub it will ever see.
Nothing requires sub to be readable, and putting a readable value there costs you later. An email address in sub breaks the never reassigned rule the first time someone changes address and the old one gets recycled. An incrementing integer leaks how many accounts exist. An opaque random identifier avoids both and gives away nothing about the directory behind it.
The decoder shows sub under Registered claims labelled Subject with its raw value, and lists an informational item when the claim is absent. It makes no attempt to look the subject up anywhere, which is the point: the token you paste never leaves your browser, so a production subject identifier is safe to inspect.
Examples
// Client A, public subject identifier
{ "iss": "https://auth.example.com", "sub": "8f14e45fceea167a5a36dedd4bea2543" }
// Client B, pairwise subject identifier for the same end user
{ "iss": "https://auth.example.com", "sub": "Xk9d2mQ7pR4tLb1sVc8n" }Things that catch people out
- Keying a user table on sub alone breaks the day you add a second identity provider, because two issuers can legitimately emit the same subject string.
- Using an email address or username as sub means the identifier changes when the person does, and JWT consumers that cached the old value now point at nobody.
- Pairwise subjects are per client. Re-registering the application with the provider hands you a fresh set of subject identifiers and orphans every existing account row.
Try it: JWT Decoder
Paste a token to decode the header and payload, read the claims and expiry, and verify the signature in your browser. Nothing is uploaded.
JWT Decoder
LOCAL · Browser-OnlyDecode and inspect JSON Web Tokens without sending them to a server
Related JWT claims and algorithms
All jwt claims and algorithms →iss (Issuer) Claim in a JWT
The iss claim names who issued a token. What goes in it, why validators compare it byte for byte, and how the decoder displays it.
preferred_username Claim in an ID Token
The preferred_username claim carries a shorthand name for the user. Why OpenID Connect says it is neither unique nor stable, and how the decoder shows it.
email Claim in an OpenID Connect ID Token
The email claim carries the end user's email address. Why it must not be used as an account key, what scope returns it, and what the decoder shows.
aud (Audience) Claim in a JWT
The aud claim names who a token is for. Why every API must check it, how the string and array forms differ, and what the decoder shows.
exp (Expiration Time) Claim in a JWT
The exp claim sets when a JWT stops being accepted. NumericDate format, clock skew allowances, and the four expiry states the decoder shows.
nbf (Not Before) Claim in a JWT
The nbf claim marks the earliest time a JWT may be accepted. When a not before time is worth setting, and how the decoder flags a future one.
Tools for this
- JWT Decoder Free online JWT decoder - decode and inspect JSON Web Tokens without sending them to a server