designwithfocus

Domains, hosting & DNS

401 vs 403: Unauthorized and Forbidden Are Not the Same

By Design With Focus Team 7 min read
Two browser error cards labeled 401 and 403 on a desk

Short answer

401 means the request was not applied because it lacks valid credentials, and 403 means the server understood the request and refuses to fulfill it. RFC 9110 requires a WWW-Authenticate challenge on a 401. A 403 can be about permissions or about something other than the credentials. Sending the same password again is not what the 403 rule tells the client to do automatically.

Last verified against the sources listed below.

Key takeaways

  • RFC 9110 says a 401 was not applied because valid authentication credentials are missing.
  • The server generating a 401 must send a WWW-Authenticate header with at least one challenge.
  • A 403 means the server understood the request and refuses to fulfill it.
  • If credentials were sent, a 403 means the server considers them insufficient to grant access.
  • The client should not automatically repeat a 403 with the same credentials.
  • An origin may send 404 instead of 403 when it does not want to reveal that the resource exists.

401 vs 403 is a difference in what the client is supposed to try next. RFC 9110, HTTP Semantics, June 2022, says a 401 (Unauthorized) was not applied because it lacks valid authentication credentials for the target resource. A 403 (Forbidden) means the server understood the request and refuses to fulfill it.

The IETF datatracker HTML is the same document. Use 401 when a challenge could lead to a successful retry. Use 403 when you are refusing the action, including when the credentials you already accepted are not enough, or when the reason is not about credentials at all.

What is the difference?

401 asks for valid credentials. 403 refuses the request the server already understood.

MDN’s 401 page puts the contrast in one sentence: a 401 is similar to a 403, except that a 403 is returned when the request contains valid credentials but the client does not have permission. MDN’s 403 page says authenticating again makes no difference.

RFC 9110 is the longer rule, and it allows a 403 even when credentials are not the issue. The table follows the RFC, with MDN’s examples beside it.

401 Unauthorized 403 Forbidden
RFC 9110 meaning Not applied, lacks valid credentials Understood, and refused
Header the server must send WWW-Authenticate with at least one challenge No required challenge header in that section
If credentials were already sent Authorization was refused for those credentials The server considers them insufficient
What the client may do Repeat with a new or replaced Authorization header May try different credentials, and must not automatically reuse the same ones
If you want to hide the resource Not the case RFC 9110 gives for 401 The origin may send 404 instead

IANA’s status code registry lists both codes under RFC 9110 and was last updated 15 September 2025. Its note on 4xx codes says the request contains bad syntax or cannot be fulfilled. That class label covers 401 and 403 without ranking them.

When does a server send 401?

A server sends 401 when the request lacks valid credentials, and it must include a challenge.

Section 15.5.2 says the server generating a 401 MUST send a WWW-Authenticate header field with at least one challenge applicable to the target resource. If the request already included credentials, the 401 means those credentials were refused. The user agent MAY repeat the request with a new or replaced Authorization header.

If the new 401 contains the same challenge and the user agent has already tried at least once, the user agent SHOULD show the response body, because it usually holds a useful explanation.

MDN’s example is a GET /admin with no Authorization header. The response is 401 Unauthorized and WWW-Authenticate: Bearer. The challenge names the scheme.

The next request is expected to send a bearer token. MDN last modified that page on 22 June 2026. The example date inside the sample response is 2 July 2024, which is sample text, not the page’s update date.

A custom login screen is still a 401 if that is the status you return for a missing or rejected credential. The RFC requirement is the challenge header, not a particular HTML layout. Website security is the wider topic of how you check those credentials. The status code only tells the client what happened to this request.

When does a server send 403?

A server sends 403 when it understood the request and will not fulfill it.

Section 15.5.4 says the server may explain the refusal in the response body. If credentials were provided, the server considers them insufficient to grant access. The client SHOULD NOT automatically repeat the request with the same credentials.

The client MAY repeat it with new or different credentials. The same paragraph says a request might be forbidden for reasons unrelated to the credentials.

MDN’s example is a DELETE /users/123 that already sends Authorization: Bearer. The response is 403, with a JSON body whose error is InsufficientPermissions and whose message says deleting users requires the admin role. The token authenticated someone.

The role check still failed. That is the “insufficient” case in the RFC. A 403 for a reason that has nothing to do with login, such as a policy that blocks the action entirely, is the other case the RFC allows.

Hiding the object is optional. The origin MAY send 404 instead of 403 when it does not want to reveal that the forbidden target exists. MDN states the same choice.

A 404 in that situation is not proof the URL was never assigned. It is a disclosure choice.

Can a new login change the result?

A new login can change a 401. It might change a 403 only if the refusal was about which credentials you sent.

On a 401, a different Authorization header is the retry the RFC permits. The challenge names the scheme. If that second 401 repeats the same challenge and the client has already tried once, RFC 9110 says the user agent should show the response body.

On a 403, automatic retry with the same credentials is what the client should not do. A person who can obtain a different account, with the admin role in MDN’s example, may try again. That is the “MAY repeat with new credentials” sentence.

If the refusal is unrelated to credentials, another login will not help. Your API should say which of those it is, in the body, when you are willing to say it. The status line alone does not carry the role name.

Do not treat the two codes as a style choice for the same lock. If the client could succeed by authenticating, 401 plus WWW-Authenticate is the RFC path. If the client is authenticated and still not allowed, or the action is forbidden for another reason, 403 is the path. Mixing them makes clients prompt for a password that cannot work, or fail silently when a login would have worked.

What should the error page show?

Show a short reason when you are willing to disclose it, and do not invent a server default.

RFC 9110 says a 403 may describe the reason in the content, and that a 401’s body is usually diagnostic once the challenge has been repeated. MDN’s 403 sample puts a machine-readable error name and a human sentence in JSON. An HTML page can do the same job for a browser: say whether the person needs to sign in, or whether this account cannot do the action.

Skip the detail if revealing the resource is the problem, and consider the 404 option instead.

Neither RFC 9110 nor the MDN status pages set a default body for Nginx, Apache, or any other server. Those products can be configured. Their stock pages are outside the documents this article uses.

Web hosting is where that server runs. The status code is still the HTTP meaning above, whoever generates it.

A custom error page can carry a favicon like any other HTML page. The Favicon Generator adds a favicon to that page. The icon does not change the status. The status line and, for 401, the WWW-Authenticate header do.

Frequently asked questions

What class of code are 401 and 403?

IANA's status code registry groups 4xx as client errors: the request contains bad syntax or cannot be fulfilled. 401 and 403 sit in that class. The registry, last updated 15 September 2025, lists 401 Unauthorized at RFC 9110 section 15.5.2 and 403 Forbidden at section 15.5.4. The 4xx label does not mean the person typed a URL wrong. It means the server is not going to do the requested thing with this request as it stands.

What does MDN add about a 403?

MDN's 403 page says this status is similar to 401, except that authenticating again makes no difference, and that the failure is tied to application logic such as missing permission. It also says a client that receives a 403 should expect the same error if it repeats the request unchanged. RFC 9110 is a bit wider: the client may try new credentials, and the refusal might be unrelated to credentials. Read MDN's summary next to that RFC paragraph, not instead of it.

What is the Bearer example on each page?

MDN's 401 example is a GET to /admin with no Authorization header. The response is 401 and WWW-Authenticate: Bearer, so the next try is expected to send a bearer token. MDN's 403 example is a DELETE to /users/123 that already sends Authorization: Bearer. The JSON body uses the error name InsufficientPermissions and says deleting users requires the admin role. One example is a missing token. The other is a token that is not allowed to do the thing.

When would a server send 404 instead?

RFC 9110 says an origin that wants to hide the current existence of a forbidden target may respond with 404 Not Found. MDN's 403 page says the same thing in plainer words: send 404 instead of 403 if you do not want to tell a client with too few privileges that the resource exists. The 404 then matches the not-found status. It does not prove the object is absent. It is a choice the origin is allowed to make.

Does a 401 always mean the password was empty?

No. RFC 9110 says that if the request already included authentication credentials, the 401 means authorization was refused for those credentials. The client may repeat the request with a new or replaced Authorization header. A wrong password and a missing password can both be 401. The required WWW-Authenticate header is what tells the client which scheme to try next, such as the Bearer scheme in MDN's example.

Sources