Whether you are interviewing for a backend, frontend, or full-stack engineering role, HTTP status codes are a staple topic. Interviewers rarely ask you to recite every code from memory; instead, they test whether you understand semantic API design, caching, authentication flows, and debugging production errors.
Here is a curated list of common HTTP status code interview questions, along with clear, practical answers.
1. What are the 5 classes of HTTP status codes?
HTTP status codes are grouped into five three-digit categories based on their first digit:
| Range | Category | Meaning |
|---|---|---|
| 1xx | Informational | The request was received, and the process is continuing. |
| 2xx | Success | The request was successfully received, understood, and accepted. |
| 3xx | Redirection | Further action must be taken by the client to complete the request. |
| 4xx | Client Error | The request contains bad syntax or cannot be fulfilled due to client input. |
| 5xx | Server Error | The server failed to fulfill an apparently valid request. |
![]()
2. What is the difference between 401 Unauthorized and 403 Forbidden?
This is one of the most frequently asked questions in web development interviews. Despite its name, 401 is actually about authentication, while 403 is about authorization.
401 Unauthorized(Unauthenticated): The server does not know who the user is. The request lacks valid authentication credentials (e.g., a missing or expired JWT, or an invalid API key). The client can fix this by logging in or refreshing their token.403 Forbidden(Unauthorized): The server knows who the user is, and their credentials are valid, but they do not have permission to access the requested resource (e.g., a standard user trying to access an/adminendpoint). Re-authenticating will not solve the issue.
3. When should you use 200 OK, 201 Created, and 204 No Content?
Using the right 2xx status code makes REST APIs predictable and easier to consume:
200 OK: The standard response for successfulGET,PUT, orPATCHrequests where a response body (such as JSON data) is returned to the client.201 Created: Used specifically when a request (typicallyPOST) results in a new resource being created on the server. Best practice is to include aLocationheader pointing to the URI of the newly created resource, along with the created object in the body.204 No Content: The request succeeded, but there is no payload to return in the response body. This is commonly used forDELETErequests orPUT/PATCHupdates where the client does not need the updated resource sent back.
4. What is the difference between 301, 302, 307, and 308 redirects?
Redirect codes differ in two ways: permanence (caching/SEO behavior) and whether the HTTP method (POST, GET, etc.) is preserved.
| Status Code | Type | Preserves HTTP Method? | Key Use Case |
|---|---|---|---|
301 Moved Permanently |
Permanent | No (browsers often change POST to GET) |
Permanent domain or URL migrations; passes SEO link equity. |
302 Found |
Temporary | No (browsers often change POST to GET) |
Temporary maintenance pages or A/B testing redirects. |
307 Temporary Redirect |
Temporary | Yes (POST stays POST) |
Temporary redirects for API endpoints or form submissions where the method/body must not change. |
308 Permanent Redirect |
Permanent | Yes (POST stays POST) |
Permanent API versioning migrations where POST/PUT requests must remain intact. |
5. Explain the difference between 400 Bad Request and 422 Unprocessable Entity.
Both indicate a problem with the data sent by the client, but they fail at different layers:
400 Bad Request: The server cannot parse or understand the request due to malformed syntax. Examples include invalid JSON formatting (a missing curly brace), corrupted query parameters, or a missing required header.422 Unprocessable Entity: The request syntax is completely valid (e.g., well-formed JSON), and the server understands the data types, but the request fails business logic or semantic validation. Examples include an email address that is already registered, a password that is too short, or a withdrawal amount exceeding an account balance.
6. How do 500, 502, 503, and 504 differ in production debugging?
In microservice and cloud architectures, knowing which 5xx code you are seeing immediately tells you where the failure occurred:
500 Internal Server Error: A generic catch-all indicating an unhandled exception or bug inside your application code (e.g., aNullPointerExceptionor a failed database query).502 Bad Gateway: An upstream server (like NGINX, a load balancer, or an API Gateway) received an invalid or corrupted response from a backend service. This often happens when the backend application crashes mid-request.503 Service Unavailable: The server is currently unable to handle the request because it is overloaded, restarting, or down for scheduled maintenance. It implies a temporary condition, and responses often include aRetry-Afterheader.504 Gateway Timeout: An upstream proxy or load balancer did not receive a timely response from the backend server before its timeout limit expired (e.g., a slow database query hanging past NGINX's 60-second limit).
7. What is 429 Too Many Requests, and how should an API implement it?
429 Too Many Requests indicates that the user has sent too many requests in a given amount of time (rate limiting).
When returning a 429, a well-designed API should include headers that help the client back off gracefully:
* Retry-After: Tells the client how many seconds to wait before making a follow-up request.
* X-RateLimit-Limit / X-RateLimit-Remaining: Informs the client of their quota and when the window resets.
8. When would you use 404 Not Found vs. 410 Gone?
404 Not Found: The server cannot find the requested resource. It makes no statement about whether the resource ever existed or might exist in the future.410 Gone: The resource used to exist at this URL, has been intentionally and permanently removed, and will not return. Search engines use410to immediately de-index removed pages, whereas404causes crawlers to check back periodically.
9. What is 304 Not Modified and how does it improve performance?
304 Not Modified is used for HTTP caching. When a client requests a resource it has previously cached, it sends conditional headers such as If-None-Match (containing an ETag. ETag: A version identifier/hash of the resource content (e.g., ETag: "v1-8f9a2c").) or If-Modified-Since (containing a timestamp).
If the resource has not changed on the server, the server responds with 304 Not Modified and an empty body. This saves bandwidth and reduces latency because the client can safely reuse its locally cached version.
10. Bonus Scenario: Which status code should you return if a user tries to access a private resource they don't own?
- Standard REST approach: Return
403 Forbiddenif the existence of the resource is not sensitive, confirming they lack permission. - Security-focused approach: Return
404 Not Foundif you want to prevent enumeration attacks (so an attacker cannot probe IDs like/api/invoices/1001and/api/invoices/1002to confirm whether those records exist).