401 Unauthorized vs 403 Forbidden

See the 401 vs 403 difference as a request sequence. 'Not logged in' (401) vs 'logged in but not allowed' (403) shown with the actual headers involved.

Scenario

Speed
401 — UNAUTHENTICATED403 — FORBIDDENBrowserServer1GET /admin2401 UnauthorizedWWW-Authenticate: Bearer401 = not authenticated (need to log in). The browser may retry with credentials — it means 'you could pass with auth'.4GET /adminAuthorization: Bearer •••5403 Forbidden403 = authenticated but forbidden. Retrying gives the same answer — you need a different account or permission. Some servers even masquerade as 404 to hide a resource's existence.

Requests

2

Current step 6/6

403 = authenticated but forbidden. Retrying gives the same answer — you need a different account or permission. Some servers even masquerade as 404 to hide a resource's existence.

Request2xx success3xx redirect/cache4xx client error5xx server error

Arrow color = status class. The key redirect pair: 301 is 'permanent', 307 'keeps the method'. Notice how cheap the second request is when the cache validates (304).

All status codes

1xx Informational

100Continue'Go ahead' before a large body — the answer to Expect: 100-continue
101Switching ProtocolsProtocol switch approved — WebSocket upgrade is the classic case
103Early HintsHeaders sent before the final response — for Link preload hints

2xx Success

200OKThe standard success response
201CreatedA new resource was created — successful POST/PUT
202AcceptedAccepted but not processed yet — async work queued
204No ContentSuccess with nothing to return — common after DELETE
206Partial ContentOnly part of the resource — Range requests, video seeking, resumed downloads

3xx Redirection

300Multiple ChoicesMultiple choices to pick from — rarely used today
301Moved PermanentlyPermanent move — remembered by browsers/search engines, SEO transfers▶ Animate
302FoundTemporary move — original URL keeps its index; POST becomes GET by convention▶ Animate
303See Other'Go GET a different URL' — the standard for redirecting after POST (PRG)▶ Animate
304Not ModifiedCache validation passed — 'use your copy', no body sent▶ Animate
305Use ProxydeprecatedForced proxy use — deprecated over security concerns
307Temporary RedirectTemporary move, method/body preserved — the precise 302▶ Animate
308Permanent RedirectPermanent move, method/body preserved — the precise 301▶ Animate

4xx Client error

400Bad RequestThe request itself is malformed — bad syntax, broken parameters
401UnauthorizedNot authenticated — credentials needed; WWW-Authenticate hints the scheme▶ Animate
402Payment RequiredPayment required — reserved, with almost no standard use
403ForbiddenAuthenticated but not allowed — retrying changes nothing▶ Animate
404Not FoundNot here right now — the most famous code▶ Animate
405Method Not AllowedRight URL, wrong method — the Allow header lists what works
406Not AcceptableCan't produce a format you Accept — content negotiation failed
407Proxy Authentication RequiredProxy authentication needed — corporate proxy environments
408Request TimeoutThe server timed out waiting for the request
409ConflictConflicts with current state — concurrent edits, version mismatch
410GoneExplicitly deleted forever — deindexes faster than 404▶ Animate
411Length RequiredContent-Length is required and missing
412Precondition FailedA precondition like If-Match didn't hold
413Content Too LargeRequest body too large — upload size limit
414URI Too LongRequest URI too long
415Unsupported Media TypeContent-Type not supported
416Range Not SatisfiableRequested Range falls outside the resource
417Expectation FailedCan't satisfy the Expect header
418I'm a teapot'I'm a teapot' — 1998 April Fools' joke; some sites reuse it for rate limiting
422Unprocessable ContentWell-formed but semantically wrong — the standard for validation failures
425Too EarlyReplay risk — rejects 0-RTT early data
426Upgrade RequiredProtocol upgrade required — Upgrade header says to what
428Precondition RequiredConditional requests required — forces If-Match against lost updates
429Too Many RequestsToo many requests — rate limiting; pairs with Retry-After
431Request Header Fields Too LargeRequest headers too large — bloated cookies are the usual cause
451Unavailable For Legal ReasonsBlocked for legal reasons — censorship, DMCA; named after Fahrenheit 451

5xx Server error

500Internal Server ErrorServer code error — the most common 5xx▶ Animate
501Not ImplementedNot implemented — the server doesn't support that method/feature
502Bad GatewayGateway couldn't reach the upstream — a middle-layer problem▶ Animate
503Service UnavailableTemporarily unavailable — overload or maintenance; pairs with Retry-After▶ Animate
504Gateway TimeoutUpstream didn't respond in time — slow queries, timeout misconfig
505HTTP Version Not SupportedThe requested HTTP version isn't supported
507Insufficient StorageServer out of storage — WebDAV
508Loop DetectedInfinite loop detected — WebDAV circular references
511Network Authentication RequiredNetwork auth required — captive portals (Wi-Fi login pages)

401 and 403 encode the authentication/authorization split. 401 means 'I don't know who you are' — not logged in, missing token, or expired credentials. The server hints at what it wants with the WWW-Authenticate header. Despite the name 'Unauthorized', it really means 'unauthenticated', which is why APIs use it as the 'log in first' signal.

403 means 'I know exactly who you are — and you're not allowed'. A normal user hitting an admin page, someone reading another user's resource. Re-authenticating won't help; you need different permissions or a different account.

The distinction leaks security information. 401 says 'you could get in with credentials'; 403 confirms 'it exists but not for you'. To hide that a sensitive resource even exists, some servers deliberately answer 404 instead — GitHub's private repos do exactly this. HTTP Status Playground

Frequently asked questions

Why am I getting 401 even with a token?
Usual causes: the token expired, the signature doesn't verify, or the Authorization header format is wrong — a missing `Bearer ` prefix is classic. 401 means 'credentials absent or invalid', so validity, not presence, is what counts.
Is it better to return 404 instead of 403?
When you want to hide a resource's existence, yes. 403 confirms 'something is here'; 404 hides whether anything exists at all. GitHub returns 404 for private repos you can't see. The trade-off: it confuses legitimate users, so apply it as a consistent policy.
Redirect to a login page, or return 401?
For browser pages, a 302 to the login page is natural UX. For APIs, return 401 and let the client handle it — a redirect chain ending in login HTML confuses API callers expecting JSON.

Other scenarios

Related tools