HTTP Status Codes

๐ŸŒ Introduction to HTTP Status Codes

Every HTTP response returned by a web server contains a numeric status code. This code informs the client about the outcome of its request. Whether a request succeeds, fails, redirects, or encounters an unexpected problem, the status code communicates the result in a standardized way.

Understanding HTTP status codes is essential for web developers, API consumers, testers, and system administrators because they simplify debugging, monitoring, and error handling.

>>"Status codes provide a universal language between clients and servers."

Information

HTTP status codes are always three-digit numbers. The first digit identifies the response category.

๐Ÿ“š Status Code Categories

1xx Informational
2xx Success
3xx Redirection
4xx Client Error
5xx Server Error

The first digit determines the overall meaning of the response. Individual codes within each category provide more specific information about what happened during request processing.

๐Ÿš€ Request Lifecycle

๐Ÿ“‚ Understanding Each Category

Informational responses indicate that the request has been received and processing continues. These codes are rarely encountered during everyday application development.

  • 100 Continue
  • 101 Switching Protocols
  • 103 Early Hints

Success responses indicate that the request completed successfully and the server fulfilled the client's request.

  • 200 OK
  • 201 Created
  • 202 Accepted
  • 204 No Content

Redirection responses tell the client that the requested resource has moved or another action is required before completing the request.

  • 301 Moved Permanently
  • 302 Found
  • 304 Not Modified
  • 307 Temporary Redirect

Client Error responses indicate that the request contains invalid data or the client lacks permission to access the resource.

  • 400 Bad Request
  • 401 Unauthorized
  • 403 Forbidden
  • 404 Not Found
  • 405 Method Not Allowed
  • 409 Conflict
  • 429 Too Many Requests

Server Error responses indicate that the server failed to process a valid request due to an internal problem.

  • 500 Internal Server Error
  • 501 Not Implemented
  • 502 Bad Gateway
  • 503 Service Unavailable
  • 504 Gateway Timeout

๐Ÿ“‹ Common HTTP Status Codes

Status CodeMeaningTypical Usage
200OKSuccessful request
201CreatedNew resource created
204No ContentSuccess without response body
301Moved PermanentlyPermanent URL change
304Not ModifiedUse cached response
400Bad RequestInvalid request
401UnauthorizedAuthentication required
403ForbiddenPermission denied
404Not FoundResource unavailable
500Internal Server ErrorUnexpected server failure
503Service UnavailableServer temporarily unavailable

๐Ÿ’ป HTTP Response Example

A successful API request typically returns a 200 OK status code.

HTTP Response

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": 1,
  "name": "Alice"
}

โŒ Example: Resource Not Found

404 Response

HTTP/1.1 404 Not Found
Content-Type: application/json

{
  "message": "User not found"
}

๐Ÿงญ Choosing the Correct Status Code

Request Received
Successful?
Yes
No
200 OK
201 Created
204 No Content
Client Problem
Server Problem
400 Series
500 Series

๐Ÿงฎ Status Code Formula

The response category can be determined mathematically using integer division.

For example, if the status code is 404, then:

Therefore, 404 belongs to the 4xx Client Error category.

โœ… Best Practices

  • Return 200 only when the request succeeds.
  • Use 201 after creating a new resource.
  • Return 204 when no response body is needed.
  • Use 400 for malformed client requests.
  • Return 401 for missing authentication and403 for insufficient permissions.
  • Never return 200 for failed operations.
  • Log all unexpected 5xx server errors for debugging.

Best Practice

Consistent use of HTTP status codes makes APIs easier to understand, test, maintain, and integrate with other applications.

๐Ÿ“– Learn More

The official HTTP Semantics specification provides complete definitions for every standardized status code.
Visit MDN HTTP Status Documentation or RFC 9110 HTTP Semantics for detailed reference material.

Summary

HTTP status codes are standardized responses that communicate the outcome of a request. Learning the meaning of the 1xx,2xx, 3xx, 4xx, and5xx categories enables developers to build reliable APIs, debug issues efficiently, and create applications that respond correctly to different server outcomes.