HTTP Status Codes Every Developer Should Actually Know
In this article
The five status-code groups Success: 200, 201, 202, 204 Redirection: 301, 302, 304, 307, 308 Client errors: 400, 401, 403, 404, 409, 422, 429 Server errors: 500, 502, 503, 504 Example: returning status codes in Express Quick reference How to choose the right codeYour endpoint returned an error. But was it a missing resource, invalid input, an authentication problem, or a server failure? HTTP status codes are the short, standard signal that tells clients what happened.
The five status-code groups
- 1xx — Informational: the request is still in progress.
- 2xx — Success: the request was received, understood, and handled.
- 3xx — Redirection: the client needs to follow another location or use a cached result.
- 4xx — Client error: the request cannot be fulfilled as sent.
- 5xx — Server error: the server failed to complete a valid request.
Success: 200, 201, 202, 204
200 OK
Use 200 when the request succeeded and you are returning a response body, such as a user profile.
HTTP/1.1 200 OK
Content-Type: application/json
{ "id": 42, "name": "Ada" }
201 Created
Use 201 when the request created a resource. Returning the created resource or a Location header is often helpful.
202 Accepted
Use 202 when work has been accepted for processing but is not complete yet, such as a background export job.
204 No Content
Use 204 when the operation succeeded and there is intentionally no response body, often after a successful delete.
Redirection: 301, 302, 304, 307, 308
301 means a resource moved permanently; 302 is a temporary redirect. 304 Not Modified tells a cache that its stored copy can be reused. The 307 and 308 redirects preserve the request method, unlike the historical method-changing behavior associated with 301/302 in some clients.
Client errors: 400, 401, 403, 404, 409, 422, 429
400 Bad Request
The request is malformed or cannot be understood—for example, invalid JSON syntax.
401 Unauthorized
Authentication is missing or invalid. Despite the name, this means the client needs valid authentication.
403 Forbidden
The server understood the request but refuses to authorize it. The user may be authenticated but lack permission.
404 Not Found
The requested resource or route was not found. APIs often use this when a record does not exist or should not be disclosed.
409 Conflict
The request conflicts with the current state, such as trying to create a username that is already taken.
422 Unprocessable Content
The syntax is valid, but the data fails validation—for example, an email field has an invalid format.
429 Too Many Requests
The client has sent too many requests in a given time. Consider returning a Retry-After header when applicable.
Server errors: 500, 502, 503, 504
500 Internal Server Error is a general unexpected failure. 502 Bad Gateway means a gateway received an invalid response from an upstream server. 503 Service Unavailable indicates temporary unavailability, and 504 Gateway Timeout means an upstream response took too long.
Example: returning status codes in Express
app.post('/api/users', async (req, res) => {
const { email } = req.body;
if (!email) {
return res.status(400).json({ error: 'Email is required' });
}
const existing = await findUserByEmail(email);
if (existing) {
return res.status(409).json({ error: 'Email already exists' });
}
const user = await createUser({ email });
return res.status(201).json(user);
});
The important part is that each response describes what happened: invalid input, a state conflict, or a newly created resource.
Quick reference
200 OK Request succeeded
201 Created Resource created
204 No Content Success, no response body
301 Moved Permanently Permanent redirect
304 Not Modified Use cached response
400 Bad Request Invalid request
401 Unauthorized Authentication required/invalid
403 Forbidden Not allowed
404 Not Found Resource not found
409 Conflict Conflicts with current state
422 Unprocessable Content Validation failed
429 Too Many Requests Rate limit reached
500 Internal Server Error Unexpected server failure
502 Bad Gateway Invalid upstream response
503 Service Unavailable Temporarily unavailable
504 Gateway Timeout Upstream timed out
How to choose the right code
- Did the request succeed? Use an appropriate 2xx code.
- Does the client need to go somewhere else? Consider a 3xx code.
- Is the request invalid, unauthenticated, forbidden, or conflicting? Choose the matching 4xx code.
- Did the server or an upstream dependency fail? Choose a suitable 5xx code.
Consistent status codes make APIs easier to debug, document, monitor, and consume. Pick the code that best describes the outcome, then keep the response body clear and predictable.