What a Status Code Is
When a browser, an API client, or a crawler sends a request, the server's answer begins with a status line such as HTTP/1.1 200 OK or, in HTTP/2, a status of 200. The code tells software what to do next: show the page, follow a redirect, ask for a password, or retry later. The words after the number are only a label; programs act on the number.
The Five Classes
| Class | Meaning | Example |
|---|---|---|
| 1xx | Informational, request continues | 101 Switching Protocols |
| 2xx | Success | 200 OK |
| 3xx | Redirection | 301 Moved Permanently |
| 4xx | Client error | 404 Not Found |
| 5xx | Server error | 500 Internal Server Error |
The Codes You Will Meet Most
| Code | Name | Meaning |
|---|---|---|
| 200 | OK | The request worked. |
| 301 | Moved Permanently | The page has a new address for good. |
| 302 | Found | A temporary redirect. |
| 304 | Not Modified | The cached copy is still current. |
| 400 | Bad Request | The request is malformed. |
| 401 | Unauthorized | Credentials are missing or wrong. |
| 403 | Forbidden | The server refuses access. |
| 404 | Not Found | Nothing exists at this address. |
| 429 | Too Many Requests | The client hit a rate limit. |
| 500 | Internal Server Error | The server failed while handling it. |
| 502 | Bad Gateway | A proxy got a bad answer from the backend. |
| 503 | Service Unavailable | The server is overloaded or in maintenance. |
| 504 | Gateway Timeout | A proxy waited too long for the backend. |
Check a Status Code with curl
curl -I https://example.com/
curl -s -o /dev/null -w '%{http_code}\n' https://example.com/
curl -IL http://example.com/
The first command prints the headers with the status line at the top. The second prints only the code, which is handy in scripts and monitoring. The third follows redirects and shows every hop. In a browser, the Network tab of the developer tools shows the code of every request on a page.
Redirects: 301, 302, 307, and 308
A 301 tells browsers and search engines that a page moved for good; use it when you change a URL or move to HTTPS. A 302 is temporary, and the old address keeps its place. 307 and 308 are the temporary and permanent versions that require the client to repeat the same method, so a form sent with POST stays a POST. Two redirects that point at each other cause ERR_TOO_MANY_REDIRECTS.
Client Errors
A 4xx code says the server will not or cannot answer this request as sent. A 401 asks for credentials, while a 403 means access is refused even with them; see 403 Forbidden in Nginx. A missing page is covered in 404 Not Found, and rate limits in 429 Too Many Requests.
Server Errors
A 5xx code says the request may well be valid and the server failed. Start with 500 Internal Server Error for application errors and 503 Service Unavailable for overload and maintenance. A 502 or 504 comes from a proxy, such as Nginx in front of PHP-FPM: the backend answered with something invalid, or not in time.
CDN Error Codes and Browser Errors
Codes from 520 upward are not part of the HTTP standard; Cloudflare uses them to report a problem between its edge and your server. The common ones are 522 (no connection), 524 (no response in time), and 525 (TLS handshake failed). Browser messages such as DNS_PROBE_FINISHED_NXDOMAIN and ERR_NAME_NOT_RESOLVED are not status codes at all: the browser never received a response.
Status Codes and Search Engines
- 301: the new address takes the old one's place in search results.
- 404 and 410: the page drops out of the index over time; 410 says the removal was intended.
- 503 and 429: Google slows its crawling and comes back later, which makes 503 the right code for short maintenance; pages that keep failing for long can drop out.
- Soft 404: a "not found" page that returns 200 may be indexed as content. Return the real code.