100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What is an HTTP Status Code?

Learn what HTTP status codes are, the five classes (1xx-5xx), common codes, and how clients use them to react to server responses.

easyQ23 of 224 in Web Development Est. time: 4 minsLast updated:
Open Code Lab

Expected Interview Answer

An HTTP status code is a three-digit number returned by a server in every HTTP response, grouped by its first digit into a class (1xx informational, 2xx success, 3xx redirection, 4xx client error, 5xx server error) that tells the client how the request was handled.

Every HTTP response includes a status line with a code and a short reason phrase, letting clients programmatically decide how to react without parsing prose. 2xx codes like 200 (OK) and 201 (Created) confirm success; 3xx codes like 301 and 302 tell the client to follow a different URL; 4xx codes like 400, 401, 403, and 404 indicate the client made a bad or unauthorized request; 5xx codes like 500 and 503 indicate the server itself failed. Choosing precise, correct status codes rather than always returning 200 is essential for clients, caches, and monitoring tools to behave correctly.

  • Lets clients react programmatically without parsing response bodies
  • Enables caches and proxies to make correct decisions
  • Standardized across all HTTP servers and clients
  • Critical for debugging and monitoring API health

AI Mentor Explanation

An HTTP status code is like the umpire’s signal after every delivery β€” a raised finger means out, a wave means no-ball, arms crossed means dead ball. Each signal is a compact, standardized code that instantly tells everyone in the ground the outcome without needing a spoken explanation. That compact, standardized outcome-signal after every action is exactly what an HTTP status code is after every request.

Step-by-Step Explanation

  1. Step 1

    Client sends a request

    The browser or client sends an HTTP request to a specific URL with a method.

  2. Step 2

    Server processes it

    The server attempts the requested operation β€” reading data, creating a resource, or validating auth.

  3. Step 3

    Server picks a status code

    It selects the code whose class and number best describe the outcome (2xx, 3xx, 4xx, 5xx).

  4. Step 4

    Client reacts to the code

    The client parses the code to decide whether to render data, redirect, retry, or show an error.

What Interviewer Expects

  • Knowledge of the five status code classes (1xx-5xx) and what each means
  • Specific familiar codes: 200, 201, 301, 302, 400, 401, 403, 404, 500, 503
  • Understanding that returning 200 for everything is an anti-pattern
  • Awareness that caches and proxies rely on correct status codes

Common Mistakes

  • Always returning 200 even when an error occurred
  • Confusing 401 (unauthenticated) with 403 (unauthorized/forbidden)
  • Not knowing which codes are cacheable by default
  • Treating status codes as decorative rather than functionally meaningful

Best Answer (HR Friendly)

β€œAn HTTP status code is a short number the server sends back with every response to say what happened β€” like 200 for success, 404 for not found, or 500 for a server error. It lets the app react correctly, like showing an error message or redirecting, without guessing from the response content.”

Code Example

Handling status codes in a fetch call
async function getUser(id) {
  const res = await fetch("/api/users/" + id);
  if (res.status === 200) {
    return res.json();
  }
  if (res.status === 404) {
    throw new Error("User not found");
  }
  if (res.status >= 500) {
    throw new Error("Server error, please retry");
  }
  throw new Error("Unexpected status: " + res.status);
}

Follow-up Questions

  • What is the difference between 401 and 403?
  • When would a server return a 3xx redirect instead of serving content directly?
  • Why is 500 usually a signal of a server bug rather than bad client input?
  • How do CDNs and browsers use status codes to decide what to cache?

MCQ Practice

1. Which status code class indicates a client error?

4xx codes indicate the client sent an invalid, unauthorized, or malformed request.

2. What does a 404 status code mean?

404 Not Found means the requested resource does not exist at that URL.

3. Which code correctly signals a resource was successfully created?

201 Created confirms a new resource was successfully created, typically returned from POST.

Flash Cards

What is an HTTP status code? β€” A three-digit code in every response indicating how the request was handled.

What does the 2xx class mean? β€” Success β€” the request was received, understood, and processed correctly.

What does the 4xx class mean? β€” Client error β€” the request was invalid, unauthorized, or malformed.

What does the 5xx class mean? β€” Server error β€” the server failed to fulfill a valid request.

1 / 4

Continue Learning