HTTP 401 Unauthorized Status Code

4xx Client Error · RFC 9110 §15.5.2 · Missing, expired, or invalid authentication credentials

401 Unauthorized RFC 9110 §15.5.2
Open /401/ →
Response & Header Builder
1m
max-age: 0s (immediate)
Editable Response Body
Live Raw HTTP Response 7 headers · 165 bytes
HTTP/1.1 401 Unauthorized
Date: Tue, 24 Nov 2026 12:00:00 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 165
Cache-Control: no-store
WWW-Authenticate: Bearer realm="api", error="invalid_token"
Content-Type: application/problem+json; charset=utf-8
X-Content-Type-Options: nosniff

{"type":"https://bytehelpers.com/http-status/401/","title":"Unauthorized","status":401,"detail":"Access token is missing or expired. Refresh credentials and retry."}
location /api/example {
    add_header Cache-Control "no-store" always;
    add_header WWW-Authenticate "Bearer realm=\"api\", error=\"invalid_token\"" always;
    add_header X-Content-Type-Options "nosniff" always;
    default_type application/json;
    return 401 '{"type":"https://bytehelpers.com/http-status/401/","title":"Unauthorized","status":401,"detail":"Access token is missing or expired. Refresh credentials and retry."}';
}
Pairwise HTTP Confusion Comparator
Open /http-status/403/ →
Attribute 401 Unauthorized 403 Forbidden
Status & Phrase401 Unauthorized403 Forbidden
Category4xx Client Error4xx Client Error
SpecificationRFC 9110 §15.5.2RFC 9110 §15.5.4
Core SemanticsIndicates 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.
Cacheable by DefaultNoNo
Method PreservationN/AN/A
Safe to Auto-RetryNo (fix request first)No (fix request first)
Response Body AllowedYesYes
Key HeadersWWW-Authenticate, Cache-Control, Content-TypeCache-Control
HTTP 401 Unauthorized Content-Length: 165 B Non-cacheable · Non-retryable
Ctrl+Enter: Copy Raw · 100% Browser-Local
Advertisement
Reserved fixed-height slot (CLS = 0.00) 728×90 320×100 300×50

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.

  • RFC SpecificationRFC 9110 §15.5.2 & RFC 6750 (OAuth2 Bearer)
  • Mandatory HeaderWWW-Authenticate describing accepted auth challenge scheme
  • 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.