HTTP status codes are three-digit numbers returned by web servers to indicate the result of an HTTP request. Understanding these codes is crucial for building robust applications, debugging API issues, and providing better user experiences.
In this comprehensive guide, you'll learn about all major HTTP status codes, what they mean, when to use them, and how to handle them in your applications. We'll cover success codes (2xx), client errors (4xx), server errors (5xx), and more.
💡 Quick Tip
Use our free JSON Validator to validate API responses and our JSON Formatter to format response data.
Definition: What Are HTTP Status Codes?
HTTP Status Codes are standardized three-digit numbers that indicate the outcome of an HTTP request. They are part of the HTTP response message and tell the client whether the request was successful, failed, or needs further action.
Status codes are organized into five categories based on their first digit:
What Status Codes Should You Know?
While there are over 60 HTTP status codes, developers typically encounter about 15-20 regularly. Here are the most important ones you should memorize:
Essential Status Codes
When to Use Each Status Code
Use status codes appropriately based on the request outcome:
2xx Success Codes - When Request Succeeds
Use when the request was processed successfully
4xx Client Errors - When Client Made a Mistake
Use when the request is invalid, unauthorized, or resource doesn't exist
5xx Server Errors - When Server Failed
Use when the server encountered an error processing the request
How to Use HTTP Status Codes: Complete Reference
2xx Success Codes
OK
When to use: Standard success response for GET, PUT, PATCH requests
Example: Fetching user data, updating a resource
Created
When to use: Resource was successfully created (POST requests)
Example: Creating a new user, adding a blog post
No Content
When to use: Request succeeded but no content to return (DELETE requests)
Example: Deleting a resource
4xx Client Error Codes
Bad Request
When to use: Request syntax is invalid or malformed
Example: Missing required fields, invalid JSON, wrong data types
Unauthorized
When to use: Authentication is required or failed
Example: Missing or invalid authentication token
Forbidden
When to use: User is authenticated but lacks permission
Example: Regular user trying to access admin endpoint
Not Found
When to use: Requested resource doesn't exist
Example: User ID doesn't exist, wrong URL path
Too Many Requests
When to use: Rate limit exceeded
Example: Too many API requests in a short time
5xx Server Error Codes
Internal Server Error
When to use: Generic server error, unexpected condition
Example: Database connection failed, unhandled exception
Bad Gateway
When to use: Server acting as gateway received invalid response
Example: Upstream server is down or unreachable
Service Unavailable
When to use: Server is temporarily unavailable (maintenance, overload)
Example: Server under maintenance, too many concurrent requests
HTTP Status Code Decision Flow
HTTP Request Received
Is request valid?
HTTP Status Code Categories Reference
| Code Range | Category | Meaning | Common Codes |
|---|---|---|---|
| 200-299 | Success | Request was successful | 200, 201, 204 |
| 300-399 | Redirect | Further action needed | 301, 302, 304 |
| 400-499 | Client Error | Request was invalid | 400, 401, 403, 404, 429 |
| 500-599 | Server Error | Server failed to process | 500, 502, 503 |
Why HTTP Status Codes Matter
Better Error Handling
Clients can handle different error types appropriately based on status codes
Improved Debugging
Status codes immediately tell you what went wrong without reading error messages
API Standards
Following HTTP standards makes your API predictable and easier to use
User Experience
Proper status codes help build better error messages and user feedback
Best Practices for Using HTTP Status Codes
Use Appropriate Codes
Don't use 200 for errors. Use 400 for client errors, 500 for server errors
Include Error Messages
Always include descriptive error messages in the response body, not just the status code
Be Consistent
Use the same status codes for the same scenarios throughout your API
Handle All Codes
Make sure your client code handles all possible status codes, not just 200