HTTP 401 Unauthorized — What It Means

What HTTP status code 401 Unauthorized means, when servers return it, and how to handle it correctly.

Published September 23, 2026

HTTP 401 Unauthorized means the request lacks valid authentication credentials. Despite the name, it is about authentication (who you are), not permission.

What it means

The server should send a WWW-Authenticate header telling the client how to authenticate. Fix it by logging in or supplying a valid token.

Common causes: Missing or expired token; Wrong password or API key; Missing Authorization header.

On the wire

GET /api/me HTTP/1.1
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer
A typical 401 exchange.

Practical examples

Test it from the shell

curl -i https://example.com/path   # look for HTTP 401

Handling 401 in code or config

if (!user) return res.status(401).set('WWW-Authenticate','Bearer').json({ error: 'Login required' })

How to fix it

Send a valid Authorization header; Refresh an expired token; Check the auth scheme (Bearer, Basic).

1. Reproduce: curl -i <url>
2. Confirm the status is 401
3. Apply the fix above and re-test

Common mistakes

  • Send a valid Authorization header
  • Refresh an expired token
  • Ignoring the response headers that explain the details.

Key takeaways

  • 401 means Unauthorized.
  • HTTP 401 Unauthorized means the request lacks valid authentication credentials.
  • Read the response headers and logs for the exact cause.

FAQ

401 vs 403?

401 means not authenticated; 403 means authenticated but not allowed.

Is 401 a client or server error?

It is a client error status code, in the 4xx class.

More HTTP articles