Indicates that the request lacks valid authentication credentials for the target resource; despite the historic name "Unauthorized", it specifically means unauthenticated.
The server understood the request and authenticated the caller, but refuses to authorize access to the target resource.
HTTP 401 Unauthorized vs 403 Forbidden: Authentication vs Authorization
Despite its historical HTTP/1.0 reason phrase "Unauthorized", HTTP 401 strictly represents an authentication failure: the server could not verify who the caller is because credentials are missing, expired, malformed, or cryptographically invalid. RFC 9110 mandates that every 401 response include a WWW-Authenticate header telling the client which scheme (such as Bearer or Basic) is required to authenticate.
In single-page apps and mobile SDKs, catching 401 is the standard trigger to execute a silent OAuth2 refresh-token exchange and replay the failed request once. Never return 401 for RBAC permission denials (where the user is logged in but lacks admin rights)—doing so traps refresh interceptors in an infinite retry loop; return 403 Forbidden instead.
401 vs 403 Rule401 = Who are you? (AuthN) · 403 = You cannot do that (AuthZ)
What is the exact difference between 401 Unauthorized and 403 Forbidden?
401 means the caller is unauthenticated (missing, invalid, or expired credentials) and authenticating may succeed. 403 means the server authenticated the caller, but their role or scope forbids access.
Is the WWW-Authenticate header mandatory on HTTP 401 responses?
Yes. RFC 9110 §15.5.2 states that a server generating a 401 response MUST send a WWW-Authenticate header containing at least one applicable authentication challenge.
Why does my API return 401 even when I pass an Authorization header?
Check for a missing "Bearer " prefix, an expired JWT exp claim, a cross-origin 301/302 redirect stripping the Authorization header, or a reverse proxy failing to forward the header.