What's the difference?
401vs403
Both say no. Watch what happens next: one can be fixed by the client, the other cannot.
- 401No credentials. The app sends 401, the client attaches a token and tries again, and it works.
- 403The token is valid. The app knows who is asking and refuses anyway. There is nothing to try again with.
How to tell them apart in 10 seconds
| Clue | 401 | 403 |
|---|---|---|
| What it means | Not authenticated: who are you? | Not permitted: I know you, and no |
| Who sends it | Typically the app or API gateway that checks credentials | Typically the app; or a CDN or proxy firewall rule |
| Header to look for | WWW-Authenticate, naming the scheme and often the reason | None. Its absence is the hint |
| What fixes it | Log in, or refresh the token | A change of role, ownership or firewall rule |
| Retry? | Once, after getting new credentials | No. The same request gets the same answer |
What it means
- 401
- Not authenticated: who are you?
- 403
- Not permitted: I know you, and no
Who sends it
- 401
- Typically the app or API gateway that checks credentials
- 403
- Typically the app; or a CDN or proxy firewall rule
Header to look for
- 401
- WWW-Authenticate, naming the scheme and often the reason
- 403
- None. Its absence is the hint
What fixes it
- 401
- Log in, or refresh the token
- 403
- A change of role, ownership or firewall rule
Retry?
- 401
- Once, after getting new credentials
- 403
- No. The same request gets the same answer
In short
401 vs 403: the difference
401: the server does not know who you are. 403: it knows, and the answer is still no.
The two codes answer different questions. A 401 Unauthorized is about identity: the request had no credentials, or they were expired or wrong, so the server cannot tell who is asking. The response should carry a WWW-Authenticate header, and the client can fix the problem by logging in or refreshing its token and sending the request again. A 403 Forbidden is about permission: the server understood the request, usually knows exactly who sent it, and refuses anyway. Sending the same credentials again changes nothing; someone has to change a role, a rule or an access list. A 403 also comes from firewalls at the edge, where no account is involved at all. Real APIs are not always this tidy, and some use 403 for a missing token or 404 to hide both.
Your turn
Which one is this?
Which one is this? A logged-in user with the “viewer” role clicks Delete. The token is valid and unexpired. The app refuses the request.
Each code in depth
Questions
- What is the difference between 401 and 403?
- A 401 means the request lacks valid credentials, so the server does not know who is asking. A 403 means the server refuses the request even though it understood it, usually because the account is not allowed.
- Should a missing token return 401 or 403?
- 401, following the standard, together with a WWW-Authenticate header. A 403 is for requests that are understood and refused, typically when valid credentials are not sufficient.
- Will logging in again fix a 403?
- Not with the same account. A 403 means that account is not allowed, or that a firewall rule blocked the request. Someone has to change the permission or the rule.
Sources: RFC 9110: 401 Unauthorized (section 15.5.2) ↗ · RFC 9110: 403 Forbidden (section 15.5.4) ↗ · Report a problem
Diagrams are our own simulations. All wording is original and paraphrases the linked sources.
Practise this in the DNS / HTTP track
Two-minute animated lessons, then boss fights from real outages. Free, no account needed.