HTTP Status Codes and Methods: Worked Traces from 2xx to 5xx

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

An HTTP status code is the three-digit number a server sends back to say what happened to a request; its first digit gives the class: 1xx informational, 2xx success, 3xx redirection, 4xx client error and 5xx server error. HTTP methods such as GET, POST, PUT and DELETE say what the client wants done. Exam questions give you a scenario and ask for the right code or method, or ask what a trace of requests leaves behind. Web Development carries 10% of the NSCT according to HEC's Areas of Competencies, and it had the highest accuracy of any area in 2026, at 54.1%, per the HEC NSCT report and APP, so careless slips cost you more here than anywhere.

The topic page Web Architecture & Protocols introduces the methods and the common codes. This page goes further: full method properties, decision rules for the 4xx and 5xx families, redirect behaviour, and numerical traces of range requests and logs. Definitions follow RFC 9110 (HTTP Semantics, 2022), which replaced RFC 7231.

The method, step by step

  1. Pick the class first. Did it work (2xx), go elsewhere (3xx), fail because of the client (4xx) or fail because of the server (5xx)?
  2. Then pick the code inside the class using the decision rules below. Watch for wording such as "permanently", "the method must not change", "already logged in" or "the upstream server".
  3. For method questions, check two properties. Safe means read-only in intent. Idempotent means N identical requests leave the same server state as one.
  4. For traces, track the server state, not the responses. Write the resource list after every request.
  5. Unknown code? RFC 9110 says treat it as the x00 code of its class: 499 is handled like 400.

Methods: safe, idempotent and cacheable

Method Safe Idempotent Typical use
GET Yes Yes Read a resource
HEAD Yes Yes Headers only, no body
OPTIONS Yes Yes Ask which methods are allowed (CORS preflight)
TRACE Yes Yes Loop-back test, usually disabled
PUT No Yes Create or replace at a known URL
DELETE No Yes Remove a resource
POST No No Create in a collection, submit forms, run actions
PATCH (RFC 5789) No Not guaranteed Partial update
CONNECT No No Open a tunnel through a proxy

Responses to GET and HEAD are cacheable by default; POST responses are cacheable only with explicit freshness information, which is rare in practice.

GET vs POST. GET puts data in the URL, so it is visible in history and logs, bookmarkable and cacheable. POST puts data in the body, so it suits passwords, file uploads and anything that changes state. HTTPS encrypts both on the wire; the URL problem is where it is stored afterwards.

Worked trace. Start with an empty /notes collection:

# Request Typical response Notes left on server
1 POST /notes 201 Created, Location: /notes/1 1
2 POST /notes (same body) 201 Created, Location: /notes/2 1, 2
3 PUT /notes/2 (new text) 200 OK 1, 2 (2 replaced)
4 PUT /notes/2 (same text again) 200 OK 1, 2 (unchanged)
5 DELETE /notes/1 204 No Content 2
6 DELETE /notes/1 404 Not Found 2
7 GET /notes/1 404 Not Found 2

Rows 1 and 2 show POST is not idempotent: repeating it made a duplicate. Rows 3 and 4 and rows 5 and 6 show PUT and DELETE are idempotent, because the state after the repeat is unchanged even though the DELETE responses differ.

The five HTTP status classes with common codes: 1xx informational, 2xx success, 3xx redirection, 4xx client error and 5xx server error.
The five status classes and the codes this page covers. The first digit alone tells you who should act.

2xx: success

Code Use it when
200 OK Success with a body (GET result, update result)
201 Created A new resource now exists; send Location with its URL
202 Accepted Accepted for processing, not finished yet (async jobs)
204 No Content Success, nothing to send back (typical for DELETE)
206 Partial Content Only the requested byte range is sent

Worked example: range requests. A file is 8,192 bytes, numbered 0 to 8,191. Ranges are inclusive at both ends.

Range header Bytes sent Content-Range in the 206 response
bytes=1000-1999 1,000 bytes 1000-1999/8192
bytes=-1024 (last 1,024) 1,024 bytes 7168-8191/8192
bytes=4096- (to the end) 4,096 bytes 4096-8191/8192
bytes=9000-9999 none 416 Range Not Satisfiable, Content-Range: bytes */8192

A paused download of a 5,000,000-byte file that already has 3,000,000 bytes resumes with Range: bytes=3000000- and receives the remaining 2,000,000 bytes.

3xx: redirects and caching

Code Permanent? May POST become GET? Typical use
301 Moved Permanently Yes Allowed (historically done by browsers) Old URL to new URL, HTTP to HTTPS for pages
302 Found No Allowed (historically done) Short-term moves
303 See Other No Yes, always GET Post/Redirect/Get after a form
307 Temporary Redirect No No, method and body kept Temporary move of an API endpoint
308 Permanent Redirect Yes No, method and body kept Permanent move of an API endpoint
304 Not Modified Not a real redirect n/a Answer to a conditional GET: "use your cached copy"

301 and 308 responses are cacheable by default, so browsers may keep following them after you remove them. Use 302 or 307 for anything you plan to undo.

Worked example: what 304 saves. A 50 KB stylesheet (51,200 bytes) is requested 1,000 times a day by returning visitors. Without validation, that is 51,200,000 bytes. With If-None-Match and a matching ETag, each answer is a 304 of about 300 bytes of headers, 300,000 bytes in all: a saving of about 99.4%.

4xx: client errors, decision rules

418 "I'm a teapot" began as an April Fools' joke; RFC 9110 lists 418 as unused, reserved so nobody assigns it.

5xx: server errors

Code Meaning Typical cause
500 Internal Server Error Unexpected failure Unhandled exception in the app
501 Not Implemented Server does not support the method at all Unknown method
502 Bad Gateway Proxy got an invalid or no response from upstream App crashed, connection refused
503 Service Unavailable Temporarily unable to handle requests Overload or maintenance; send Retry-After
504 Gateway Timeout Proxy waited too long for upstream Slow database query behind the app

Worked example: reading a log. A server logged these 20 codes: 200, 200, 301, 200, 404, 304, 200, 500, 201, 200, 403, 304, 200, 503, 204, 404, 200, 302, 429, 200.

Class Codes Count
2xx eight 200s, 201, 204 10
3xx 301, 304, 304, 302 4
4xx 404, 403, 404, 429 4
5xx 500, 503 2

Error rate = (4 + 2) / 20 = 30%; server-error rate = 2 / 20 = 10%. 304s are not errors: they are successful cache revalidations.

Speed tricks

Common mistakes

Practice set

  1. Which code should a successful PUT that created a brand-new resource return?
  2. A file is 2,000 bytes. What does Range: bytes=500- return?
  3. A POST to /checkout gets 303 with Location /thank-you. What does the browser send next?
  4. An API does not support PATCH on /reports at all, but supports GET. Which code and header?
  5. A database query behind the app takes 90 seconds, and the load balancer gives up at 60. Which code?
  6. In a log of 40 responses, 6 are 4xx and 2 are 5xx. Error rate?
  7. Is a GET request allowed to change data on the server, according to RFC 9110?
  8. A client keeps retrying after a 503 with Retry-After: 120. When should it try again?
  9. Which code means "request body is valid JSON, but the server only accepts XML bodies"?
Show answers
  1. 201 Created. Replacing an existing one returns 200 or 204.
  2. 206 with bytes 500-1999/2000, which is 1,500 bytes.
  3. GET /thank-you, without the form body.
  4. 405 Method Not Allowed with Allow: GET (plus HEAD if supported).
  5. 504 Gateway Timeout.
  6. 20%. 8 / 40.
  7. No. GET is safe: the client does not request a state change, so links and crawlers can follow it.
  8. After 120 seconds.
  9. 415 Unsupported Media Type.

Practise

The quiz below has 20 questions on HTTP status codes and methods, filterable by tier and difficulty. The range arithmetic was computed in Python, the log question was run, and reason phrases were checked against Python's http.HTTPStatus, which uses RFC 9110 names.

Practise: 20 questions

Interactive quiz loading. The first 10 questions are shown below.

  1. An API starts a video-encoding job that will finish in a few minutes and returns immediately with a link to check progress. Which status code fits?

    1. 200 OK
    2. 201 Created
    3. 202 Accepted
    4. 204 No Content
    Show answer

    Answer: C. 202 Accepted

    RFC 9110 defines 202 Accepted for a request that has been accepted for processing but not completed, which suits asynchronous jobs. 201 means the resource already exists, 200 means the work is done, and 204 means success with no body.

  2. A news site deliberately removes an old article for good and wants clients and crawlers to know it will not come back. Which code says that most precisely?

    1. 404 Not Found
    2. 410 Gone
    3. 403 Forbidden
    4. 301 Moved Permanently
    Show answer

    Answer: B. 410 Gone

    410 Gone means the resource is no longer available and the condition is likely permanent. 404 only says nothing was found, without saying whether that is permanent. 301 is for content that moved to a new URL.

  3. A logged-in student requests the admin dashboard. The server knows who she is but she lacks the admin role. Which code is correct?

    1. 403 Forbidden
    2. 401 Unauthorized
    3. 404 Not Found
    4. 400 Bad Request
    Show answer

    Answer: A. 403 Forbidden

    403 Forbidden means the server understood the request and the identity but refuses it; logging in again will not help. 401 is for missing or invalid credentials. A server may use 404 to hide that the page exists, but 403 is the direct answer.

  4. According to RFC 9110, which header must a server send with a 401 Unauthorized response?

    1. Authorization
    2. Location
    3. Retry-After
    4. WWW-Authenticate
    Show answer

    Answer: D. WWW-Authenticate

    A 401 response must include a WWW-Authenticate header with at least one challenge telling the client how to authenticate (for example Basic or Bearer). The client replies with an Authorization header. Location goes with redirects and 201; Retry-After goes with 503 and 429.

  5. A registration API receives well-formed JSON, but the age field is -5. Which status code best describes this, using RFC 9110's names?

    1. 422 Unprocessable Content
    2. 400 Bad Request, because all invalid input is 400
    3. 415 Unsupported Media Type
    4. 409 Conflict
    Show answer

    Answer: A. 422 Unprocessable Content

    422 means the server understands the content type and the syntax is correct, but it cannot process the contained instructions, such as a failed validation rule. Many APIs use 400 for this too; 400 is the better fit for malformed syntax. 415 is about the media type and 409 about a clash with the resource's current state.

  6. A client library receives status code 432, which it does not recognise. How does RFC 9110 say it should treat the response?

    1. As 200 OK, because a response arrived
    2. As 500, because unknown codes mean server failure
    3. As a network error, and retry the request
    4. As 400 Bad Request, the generic code of its class
    Show answer

    Answer: D. As 400 Bad Request, the generic code of its class

    RFC 9110 says a client must understand the class of any status code by its first digit and treat an unrecognised code as the x00 code of that class. 432 is in the 4xx class, so it is handled like 400.

  7. A video file is 10,000 bytes long. A client sends Range: bytes=0-499 and the server supports ranges. What comes back?

    1. 206 Partial Content with 499 bytes
    2. 206 Partial Content with 500 bytes
    3. 200 OK with the whole 10,000 bytes
    4. 416 Range Not Satisfiable
    Show answer

    Answer: B. 206 Partial Content with 500 bytes

    Byte ranges are inclusive at both ends, so 0-499 is 499 - 0 + 1 = 500 bytes. A server that honours ranges answers 206 Partial Content with Content-Range: bytes 0-499/10000. A server may ignore Range and send 200, but this one supports ranges.

  8. For the same 10,000-byte file, a client sends Range: bytes=-500. Which Content-Range header does the 206 response carry?

    1. Content-Range: bytes 0-500/10000
    2. Content-Range: bytes 9499-9999/10000
    3. Content-Range: bytes 9500-9999/10000
    4. Content-Range: bytes 9500-10000/10000
    Show answer

    Answer: C. Content-Range: bytes 9500-9999/10000

    A suffix range -500 asks for the last 500 bytes. Bytes are numbered 0 to 9,999, so the last 500 are 9,500 to 9,999 inclusive. 9499-9999 would be 501 bytes, and 10000 is past the end.

  9. For the same 10,000-byte file, a client sends Range: bytes=12000-12999. What should a server that supports ranges return?

    1. 206 Partial Content with 0 bytes
    2. 200 OK with the whole file
    3. 404 Not Found, because those bytes do not exist
    4. 416 Range Not Satisfiable with Content-Range: bytes */10000
    Show answer

    Answer: D. 416 Range Not Satisfiable with Content-Range: bytes */10000

    The first requested byte (12,000) is beyond the end of the 10,000-byte file, so no part of the range can be served. RFC 9110 uses 416 for this and recommends Content-Range: bytes */10000 so the client learns the real length. The file itself exists, so 404 is wrong.

  10. A client sends PUT /docs/7 with If-Match: "v3" to avoid overwriting someone else's edit. The document's current ETag is "v4". What should the server return?

    1. 304 Not Modified
    2. 409 Conflict
    3. 412 Precondition Failed
    4. 200 OK, after saving the new version
    Show answer

    Answer: C. 412 Precondition Failed

    If-Match makes the update conditional: the ETags differ, so the precondition is false and the server must not apply the PUT; it answers 412 Precondition Failed. 304 is for conditional GET or HEAD with If-None-Match or If-Modified-Since.

FAQs

What is the difference between 401 and 403?

401 Unauthorized means the request has no valid credentials; the response must carry a WWW-Authenticate challenge, and logging in may fix it. 403 Forbidden means the server knows or does not need your identity and still refuses. Logging in again will not help, because the problem is permission, not identity.

Is POST idempotent?

No. Each POST may create a new resource or trigger a new action, so sending the same POST twice can create two orders or two charges. PUT and DELETE are idempotent. To make POST retries safe, many payment APIs accept an idempotency key that lets the server recognise a repeat.

Which status code should an API return for validation errors?

RFC 9110 offers 422 Unprocessable Content for well-formed requests whose content fails validation, and 400 Bad Request for malformed syntax. Many APIs use 400 for both. In an exam, choose 422 when the stem stresses that the syntax is valid but a value breaks a rule.

What is the difference between 301 and 308?

Both are permanent redirects and both are cacheable by default. The difference is the method: after a 301, browsers historically switch POST to GET, while a 308 must repeat the same method and body. Use 308 when moving API endpoints that receive POST or PUT.

Next step

Revise the foundations in Web Architecture & Protocols, then apply these codes in Web APIs & Integration. Return to the Web Development MCQ hub or take the NSCT mock test.