What do HTTP status codes mean? Explain the 1xx to 5xx classes.
EasyConceptDNS, HTTP & HTTPS
Answer
A status code is the three-digit number in every HTTP response that tells the client what happened. The first digit gives the class.
| Class | Meaning | Common codes |
|---|---|---|
| 1xx | informational | 100 Continue, 101 Switching Protocols |
| 2xx | success | 200 OK, 201 Created, 204 No Content |
| 3xx | redirection | 301 Moved Permanently, 302 Found, 304 Not Modified |
| 4xx | client error | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found |
| 5xx | server error | 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable |
- 401 vs 403: 401 means the client is not authenticated, so it should log in and retry; 403 means it is authenticated but not allowed.
- A 4xx code means the client must fix the request; a 5xx code means the server failed on a valid request, so retrying later may succeed.
Example:
GET /profile (no login token) -> 401 Unauthorized
GET /admin (token of a student) -> 403 Forbidden
GET /old-page -> 301 Moved Permanently, Location: /new-page
GET /no-such-page -> 404 Not Found
GET /orders (database is down) -> 500 Internal Server Error