HTTP status codes
Table of Contents
HTTP Status Codes
Description
HTTP Status Codes are a fundamental part of the Hypertext Transfer Protocol (HTTP). Every time a client (such as a web browser or an application) sends a request to a server, the server responds with a status line that includes a code and a short message explaining the result.
Structure and Purpose
The code is a three-digit integer where the first digit defines the class or category of the response, providing a standardized way for the client to understand what happened without needing to parse the full response body.
The five standard classes of status codes are:
| Class | Range | Meaning |
|---|---|---|
| 1xx | 100-199 | Informational – The request was received and processing is continuing. |
| 2xx | 200-299 | Success – The request was successfully received, understood, and accepted. |
| 3xx | 300-399 | Redirection – Further action must be taken to complete the request. |
| 4xx | 400-499 | Client Error – The request contains bad syntax or cannot be fulfilled. |
| 5xx | 500-599 | Server Error – The server failed to fulfill an apparently valid request. |
Role in Networking
Status codes are vital for:
- Caching: Codes like 304 Not Modified tell the client that the cached version of the resource is still valid, saving bandwidth and speeding up page loads.
- Search Engine Optimization (SEO): Codes like 301 Moved Permanently are used by search engine spiders to transfer link authority to a new URL.
- Debugging: Developers and administrators use the codes to quickly diagnose why an application or service is failing (e.g., a 403 Forbidden indicates a permission issue, while a 503 Service Unavailable indicates a server capacity or maintenance issue).
Examples
Common Status Codes
| Code | Status Message | Class | Purpose |
|---|---|---|---|
| 200 | OK | Success | Standard response for successful HTTP requests. |
| 201 | Created | Success | The request has been fulfilled and resulted in a new resource being created (e.g., after a POST request). |
| 301 | Moved Permanently | Redirection | The requested resource has been permanently moved to a new URL. |
| 302 | Found | Redirection | The requested resource resides temporarily under a different URI. |
| 304 | Not Modified | Redirection | Used for caching. Tells the client the resource has not changed since the last request. |
| 400 | Bad Request | Client Error | The server cannot process the request due to a client error (e.g., malformed syntax). |
| 401 | Unauthorized | Client Error | Authentication is required and has failed or not yet been provided. |
| 403 | Forbidden | Client Error | The server understood the request but refuses to authorize it (permission issue). |
| 404 | Not Found | Client Error | The requested resource could not be found. |
| 500 | Internal Server Error | Server Error | A generic error message, returned when no more specific message is suitable. |
| 503 | Service Unavailable | Server Error | The server is currently unable to handle the request due to temporary overload or maintenance. |