HTTP Status Codes and Methods: Worked Traces from 2xx to 5xx
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
- Pick the class first. Did it work (2xx), go elsewhere (3xx), fail because of the client (4xx) or fail because of the server (5xx)?
- 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".
- For method questions, check two properties. Safe means read-only in intent. Idempotent means N identical requests leave the same server state as one.
- For traces, track the server state, not the responses. Write the resource list after every request.
- 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.

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
- Request syntax broken (malformed JSON)? 400 Bad Request.
- No valid credentials? 401 Unauthorized, which must include
WWW-Authenticate. - Known user, not allowed? 403 Forbidden. A server may send 404 instead to hide that the resource exists.
- Nothing at that URL? 404 Not Found; gone for good on purpose? 410 Gone.
- Method not supported for this resource? 405 Method Not Allowed with an
Allowheader. - Cannot produce a format the
Acceptheader wants? 406 Not Acceptable. Cannot read the body'sContent-Type? 415 Unsupported Media Type. - Clashes with the resource's current state? 409 Conflict. An
If-MatchorIf-Unmodified-Sincecheck failed? 412 Precondition Failed. - Body too big? 413 Content Too Large (RFC 9110's new name for "Payload Too Large").
- Valid syntax but fails validation? 422 Unprocessable Content; many APIs use 400 here too.
- Too many requests from this client? 429 Too Many Requests (defined in RFC 6585), ideally with
Retry-After.
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
- First digit decides the class; only then argue about the exact code.
- "Who are you?" = 401; "I know you, but no" = 403.
- Method kept on redirect = 307 or 308 (the "7 and 8 keep it straight" rule); 303 always switches to GET.
- Inclusive ranges: length = last - first + 1.
- Proxy in the story? It is almost always 502 or 504.
Common mistakes
- Treating 401 as "forbidden"; it means unauthenticated.
- Saying DELETE is not idempotent because the second call returns 404.
- Using 200 with an error message in the body; clients and monitoring then see success.
- Using 301 for a temporary promotion, then fighting browser caches.
- Mixing up 406 (the response format) and 415 (the request body format).
- Counting a byte range as last - first and losing one byte.
Practice set
- Which code should a successful PUT that created a brand-new resource return?
- A file is 2,000 bytes. What does
Range: bytes=500-return? - A POST to /checkout gets 303 with Location /thank-you. What does the browser send next?
- An API does not support PATCH on /reports at all, but supports GET. Which code and header?
- A database query behind the app takes 90 seconds, and the load balancer gives up at 60. Which code?
- In a log of 40 responses, 6 are 4xx and 2 are 5xx. Error rate?
- Is a GET request allowed to change data on the server, according to RFC 9110?
- A client keeps retrying after a 503 with
Retry-After: 120. When should it try again? - Which code means "request body is valid JSON, but the server only accepts XML bodies"?
Show answers
- 201 Created. Replacing an existing one returns 200 or 204.
- 206 with bytes 500-1999/2000, which is 1,500 bytes.
- GET /thank-you, without the form body.
- 405 Method Not Allowed with
Allow: GET(plus HEAD if supported). - 504 Gateway Timeout.
- 20%. 8 / 40.
- No. GET is safe: the client does not request a state change, so links and crawlers can follow it.
- After 120 seconds.
- 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
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.