What do the major HTTP status code categories (2xx, 3xx, 4xx, 5xx) mean?
Understand HTTP status code categories 2xx, 3xx, 4xx and 5xx, what each means, and how clients use the first digit to handle success, redirects and errors.
Expected Interview Answer
HTTP status codes are grouped by their first digit: 2xx means success, 3xx means redirection, 4xx means a client-side error, and 5xx means a server-side error.
The first digit signals the class of outcome so clients can react without parsing every specific code. 2xx (e.g. 200, 201, 204) confirms the request succeeded; 3xx (301, 302, 304) tells the client the resource moved or is unchanged; 4xx (400, 401, 403, 404, 429) blames the request itself; 5xx (500, 502, 503) means the server failed while handling a valid request. There is also 1xx for informational responses, which is rarely used directly.
- Clients can branch on the category without knowing every code
- Clearly separates client faults from server faults
- Enables correct retry and caching behaviour
- Improves observability and error dashboards
- Standardised across every HTTP framework and tool
AI Mentor Explanation
Think of the umpire's signals during a match. A raised finger for out or a wide-spread arm for a wide are like 2xx and 4xx: each gesture belongs to a family that everyone in the ground instantly recognises. A signal to the third umpire is a 3xx redirect, and the match being abandoned due to a pitch failure is a 5xx server fault — the players did nothing wrong, the venue itself broke.
Step-by-Step Explanation
Step 1
Read the first digit
The leading digit alone tells you the outcome class before you inspect the exact code.
Step 2
2xx — success
The request was received, understood and accepted: 200 OK, 201 Created, 204 No Content.
Step 3
3xx — redirection
Further action is needed or the resource moved: 301 Moved Permanently, 302 Found, 304 Not Modified.
Step 4
4xx — client error
The request was malformed or unauthorised: 400 Bad Request, 401, 403, 404, 429 Too Many Requests.
Step 5
5xx — server error
The server failed to fulfil a valid request: 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable.
What Interviewer Expects
- Correct meaning of each category by first digit
- At least one concrete code per category
- Distinction between 4xx (client) and 5xx (server) fault
- Awareness that 4xx should not be retried blindly but 5xx often can
- Mention of caching relevance for 304
Common Mistakes
- Confusing 4xx and 5xx responsibility
- Thinking every non-200 code is an error
- Forgetting 3xx exists as its own category
- Assuming 200 always means the operation logically succeeded
- Not knowing 204 returns no body
Best Answer (HR Friendly)
“HTTP status codes are grouped by their first number: the 200s mean it worked, the 300s mean go somewhere else, the 400s mean the request was wrong, and the 500s mean the server itself had a problem. That first digit lets any app quickly understand the result.”
Code Example
const res = await fetch('/api/orders/42')
if (res.status >= 200 && res.status < 300) {
const data = await res.json() // 2xx success
return data
} else if (res.status >= 400 && res.status < 500) {
throw new Error('Client error, fix the request: ' + res.status)
} else if (res.status >= 500) {
// 5xx: server side, safe to retry with backoff
return retryWithBackoff(() => fetch('/api/orders/42'))
}Follow-up Questions
- What is the difference between 301 and 302?
- When would you return 201 versus 200?
- Why is 304 Not Modified important for caching?
- Which status codes are safe to retry automatically?
- What does 429 Too Many Requests signal to a client?
MCQ Practice
1. A response with status 503 belongs to which category?
503 Service Unavailable starts with 5, so it is a server-side error meaning the server could not handle a valid request.
2. Which category indicates the client sent a bad or unauthorised request?
4xx codes such as 400, 401, 403 and 404 indicate the fault lies with the client's request.
3. Which status code means success with no response body?
204 No Content confirms the request succeeded but there is intentionally no body to return.
Flash Cards
2xx means? — Success — the request was received, understood and accepted (200, 201, 204).
3xx means? — Redirection — the resource moved or further action is needed (301, 302, 304).
4xx means? — Client error — the request was malformed or unauthorised (400, 401, 403, 404, 429).
5xx means? — Server error — the server failed to fulfil a valid request (500, 502, 503).
Which class is safe to retry? — 5xx errors are often transient and retryable; 4xx usually needs the request fixed first.