Reference guide · http-status · Published 2026-08-15 · 4 min read

HTTP 401 unauthorized explained

HTTP 401 unauthorized explained: the status means authentication failed, not authorization. How 401 differs from 403 and how clients, servers and security tools behave.

What a 401 means

A 401 Unauthorized is the server saying: "I need you to identify yourself, and you have not, or the credentials you sent are wrong." The client can answer by supplying the right evidence for that request, and the same URL is then serveable. It is not the same as forbidden: a 403 means you are known to the server and still not allowed to read the file.

In HTTP, the header the server uses to offer the challenge is WWW-Authenticate, and the client answers in Authorization. Here is the pair:

HeaderTravels routeExample
WWW-AuthenticateServer to client, carries the challengeWWW-Authenticate: Basic realm="admin"
AuthorizationClient to server, carries the evidenceAuthorization: Bearer abc.def.ghi

401 versus 403 in one view

401 Unauthorized403 Forbidden
Meaning"I do not know who you are yet""I know who you are, you cannot have it"
Real user causeBad or missing token, login neededNo permission, rule or block
Fix directionRetry with correct credentialsChange the rule, permission or block

It is easy to swap them when debugging, because a browser shows a similar error. File the status from your log, not from memory: many security gateways return 403 for odd traffic even when there was no identity at all, so the code in the log is the source of truth about your application.

How the browser and API behave

How to verify with curl

# 1. No credentials: expect 401 and a WWW-Authenticate header
curl -I https://api.example.com/private/
# HTTP/1.1 401 Unauthorized
# WWW-Authenticate: Basic realm="api"

# 2. Correct basic token
curl -u username:password -I https://api.example.com/private/
# HTTP/1.1 200 OK

# 3. Expired or wrong token (Bearer style)
curl -H "Authorization: Bearer invalid" https://api.example.com/private/
# HTTP/1.1 401

Prevent and diagnose common 401 pile-ups

Prevention

When to use which

If the request lacks any authentication evidence, return 401. If authentication succeeded but the account is not allowed to see the resource, return 403. Sending 403 for everything hides the cause and costs debugging time.

Need a website built, fixed, optimised, migrated or replaced?

This technical resource is written by CSMBAC, a small design and development studio. If you would rather hand the problem to a professional, the website service page explains how we build enquiry-ready websites.

Explore website services