HTTP Status Codes Explained: 301 vs 302, 401 vs 403, 502 vs 504

A practical guide to HTTP status code classes, the confusing pairs people mix up, and how to diagnose 4xx and 5xx errors from the client or the server.

Updated September 29, 2026 6 min read

Use the free HTTP Status CodesSearchable list of every HTTP status code with meaning and common causes

Every HTTP response starts with a three-digit number. Most of the time nobody looks at it. Then a page starts returning 502, an API call fails with 422, a search console report lists hundreds of 404s, or a load balancer shows a code you have never seen, and suddenly that number is the most useful clue you have.

This guide explains how status codes are organised, clears up the pairs that are most often confused, and gives a step-by-step way to work out whether a problem lies with the client, the application, or something in between.

The five classes

The first digit tells you the category. You can often decide where to look from that digit alone.

Class Meaning Who usually needs to act
1xx Informational: the request is in progress Nobody; rarely visible
2xx Success Nobody
3xx Redirection: look elsewhere The client follows the new location
4xx Client error: the request was wrong Whoever built the request
5xx Server error: the request may be fine, the server failed Whoever runs the server

Clients that do not recognise a specific code are expected to treat it like the x00 code of its class. An unknown 4xx behaves like 400, an unknown 5xx like 500.

Pairs that are easy to confuse

301 vs 302 (and 307 vs 308)

301 Moved Permanently says the resource has a new permanent URL. Browsers cache it, and search engines transfer the old URL's signals to the new one. 302 Found is temporary: keep using the old URL. Use 301 for domain moves and HTTPS migrations, 302 for short-lived situations such as a maintenance page.

307 and 308 are the strict versions of 302 and 301. With 301 and 302, browsers historically change a POST into a GET when following the redirect. 307 (temporary) and 308 (permanent) require the same method and body to be sent again, which matters for APIs and form submissions.

401 vs 403

401 Unauthorized actually means unauthenticated: the server does not know who you are, or the credentials are missing, wrong or expired. Logging in or refreshing a token may fix it. 403 Forbidden means the server knows or does not care who you are, and the answer is still no. Retrying with the same credentials will not help. On a plain web server, 403 often comes from file permissions or a directory without an index file.

400 vs 422

400 Bad Request means the request could not be parsed: broken JSON, an invalid header, a malformed URL. 422 Unprocessable Content means it was parsed fine but failed validation, such as an email field that is not an email. Many frameworks use 422 for form validation errors.

404 vs 410

404 Not Found makes no promise about the future. 410 Gone says the resource was removed deliberately and will not return. For content you have intentionally deleted, 410 is more precise.

500 vs 502 vs 503 vs 504

  • 500 Internal Server Error: the application itself crashed or hit an unhandled error.
  • 502 Bad Gateway: a proxy or load balancer (Nginx, a CDN, a cloud load balancer) got an invalid response or no connection from the application behind it. The app process may be down.
  • 503 Service Unavailable: the server is deliberately refusing work for now, because of maintenance or overload. It may include a Retry-After header.
  • 504 Gateway Timeout: the proxy reached the application but gave up waiting for a response. The app is alive but too slow.

The difference between 502 and 504 is the most useful one in practice: 502 points at a crashed or unreachable backend, 504 at a slow one.

Look up any code

The HTTP Status Codes reference lists standard codes with plain-English meanings and common causes.

  1. Open the HTTP Status Codes page. Codes are grouped by class, each with a heading and short description.
  2. Type into the search box. A number such as 42 shows every code starting with those digits, 5xx shows a whole class, and words like timeout, redirect or cors search the names, descriptions and causes.
  3. Use the All, 1xx, 2xx, 3xx, 4xx and 5xx buttons to filter by class.
  4. Toggle Include Nginx / Cloudflare / Laravel codes to show or hide non-standard codes such as 499, 520-526 and 419. These are marked "unofficial".
  5. Read the Common causes line on each card, and click the copy icon to copy the code and its name.

Diagnosing an error step by step

1. See the real response

Browsers sometimes show a friendly page that hides the status. Look at the Network tab in DevTools, or ask for headers only from the command line:

curl -sI https://example.com/pricing

Add -L to follow redirects and see each hop. If you want to replay a request from DevTools in code, "Copy as cURL" and then the cURL to Code converter will turn it into fetch, Python or PHP.

2. Identify who produced the code

The same 502 can come from your CDN, your load balancer or your web server. The response body and headers usually give it away: CDN error pages carry the provider's branding and headers such as server or cf-ray, while a plain Nginx error page says "nginx" at the bottom. Knowing which layer answered tells you which log to read.

3. Match the class to the log

  • For 4xx, check what the client sent: URL, method, headers, body and credentials. The server's access log shows the request exactly as received.
  • For 5xx, check the application's error log first, then the proxy's error log. A 502 in Nginx usually pairs with a line such as "connect() failed" or "upstream prematurely closed connection".

4. Handle codes correctly in code

Remember that fetch() in JavaScript does not reject on 4xx or 5xx. It resolves with response.ok set to false, so you must check it:

const res = await fetch("/api/orders");
if (!res.ok) {
  throw new Error(`Request failed: ${res.status} ${res.statusText}`);
}
const orders = await res.json();

For 429 and 503, respect Retry-After and back off instead of retrying immediately.

Codes that matter for SEO

Search engines treat status codes as instructions:

  • 200 pages can be indexed.
  • 301 and 308 consolidate signals onto the target URL; long redirect chains waste crawl effort.
  • 404 and 410 eventually remove a URL from the index.
  • 5xx responses, if they persist, slow crawling and can lead to pages dropping out.
  • A "soft 404", an error page returned with status 200, confuses crawlers. Return a real 404 status for missing pages.

If you are setting up redirects on Apache, the .htaccess redirect generator writes 301 and 302 rules, and the robots.txt tester helps confirm you are not blocking the pages you meant to keep. When a 403 turns out to be file permissions, the guide to Linux file permissions and chmod explains the fix, and a script or stylesheet refused by the browser is often a wrong MIME type rather than a status problem.

Frequently asked questions

What is the difference between 401 and 403?

401 means the server needs valid authentication and did not get it. 403 means the request is understood but not allowed, and new credentials of the same kind will not change that.

Is a 404 bad for SEO?

Not by itself. A 404 for a page that really does not exist is the correct response. Problems arise when important pages return 404 by mistake or when internal links point to missing pages.

What causes a 502 Bad Gateway?

A proxy or CDN could not get a valid response from the server behind it. Common causes are a crashed application process, a stopped PHP-FPM service or a firewall blocking the proxy.

What does status code 499 mean?

499 is an Nginx-specific code logged when the client closed the connection before the server replied. Users never see it; it appears in logs when requests take longer than the client is willing to wait.

Should an API return 200 with an error message in the body?

It is better not to. Returning a proper 4xx or 5xx lets clients, proxies and monitoring tools recognise failures without parsing the body.

Try it now: HTTP Status Codes

Loading tool…