plain/devtools home

HTTP 401 vs 403

401 Unauthorized means "I do not know who you are": credentials are missing or invalid. 403 Forbidden means "I know who you are, and you may not do this" or the server refuses regardless of who you are.

Last reviewed 2026-11-04.

http-status-codessampless sample

never leaves your browser

Worked example

An API returns data for a logged in user at /api/orders:

  • No Authorization header: respond 401, with a WWW-Authenticate header naming the scheme (RFC 9110 requires it on 401).
  • An expired or malformed token: 401. See the JWT expired error.
  • A valid token for a user without access to another user's order: 403.
  • A valid admin route called by a non-admin: 403.

Debugging each

  • 401: check the header is sent, the scheme (Bearer, Basic), the token is current and the request goes to the right environment.
  • 403: check the account's roles or scopes, IP allow lists, CORS and CSRF protections, and any firewall in front of the server.
  • Both look the same in a browser. Read the response body and headers in the network panel.

A related choice: 404

A server may return 404 instead of 403 to avoid revealing that a resource exists. RFC 9110 allows this. It is a deliberate choice, not a mistake.

Running this on a server

If you build the API yourself, the status codes are yours to choose. The hosting guide compares places to run a small API.

Frequently asked questions

Should a wrong password return 401 or 403?

401. The credentials failed, so the request is not authenticated.

Why is 401 called Unauthorized?

The name is historical. The meaning in RFC 9110 is lack of valid authentication credentials.

Does retrying help?

For 401, yes with new credentials. For 403, the same credentials will not work.

Sources

Related

esc
↑↓ move↵ open? all shortcuts

Keyboard shortcuts

Cmd or Ctrl shortcuts always work.
Everywhere
Everywhere
Open the command palette
CtrlK
Open the palette (outside a text field)
/
Show these shortcuts
?
Toggle light and dark theme
t
Go home
gh
Go to all tools
gt
On a tool page
On a tool page
Run the main action
Ctrl↵
Copy the output
c
Load the next sample
s
Focus the input
i
Leave a text field
Esc
Previous or next tool
[]
In the palette
In the palette
Move the selection
↑↓
Open the selected item
↵
Close
Esc