What the three segments contain
A JWT is three base64url strings joined by dots. Splitting on those dots and decoding the first two gives you JSON; the third is the signature and is raw bytes rather than text.
The header names the algorithm and the token type. The payload carries the claims. The signature is computed over the encoded header and payload together, which is why altering either one invalidates it.
header.payload.signature
{"alg":"HS256","typ":"JWT"}
{"sub":"1234567890","name":"Ada","iat":1516239022}
HMACSHA256(base64url(header) + "." + base64url(payload), secret)Because the signature covers the encoded forms rather than the decoded JSON, re-serialising the payload with different key order would break verification. This is why tokens are passed around as strings and never rebuilt.