Interview questions and cheat sheets
HTTP Status Codes Cheat Sheet
This cheat sheet explains the HTTP status codes you meet in real websites and APIs, grouped by class, with guidance on which one to return and why. It also covers redirects and soft 404s for SEO, caching with 304, and how to inspect responses with curl.
By CodingMarble · Published · 5 min read

The five classes
The first digit of a status code tells you the category, and a client that does not recognise a specific code should treat it like the first code of its class.
- 1xx informational: the request was received and processing continues. You rarely see these in application code.
- 2xx success: the request worked.
- 3xx redirection: the client must take another step, usually fetching a different URL.
- 4xx client error: the request was wrong, so repeating it unchanged will fail again.
- 5xx server error: the request looked valid but the server failed, so a retry later may succeed.
The class matters to crawlers, monitoring and retry logic. A 4xx is generally not retried, while a 5xx often is, so returning the wrong class changes how other systems behave.
1xx and 2xx: informational and success
- 100 Continue lets a client send a large body only after the server accepts the headers. 101 Switching Protocols is how a connection upgrades to WebSocket. 103 Early Hints lets the server send preload hints before the final response is ready.
- 200 OK is the default for a successful GET or any request that returns a body.
- 201 Created means a new resource exists after POST or PUT. Return a Location header with its URL and, normally, the new resource in the body.
- 202 Accepted means the work is queued and not yet done, which suits slow jobs such as report generation.
- 204 No Content means success with an empty body, which fits a DELETE or a PUT that has nothing to return. Do not send a body with it.
- 206 Partial Content answers a range request, which is how video seeking and resumable downloads work.
3xx: redirects
Redirects differ on two axes: permanent or temporary, and whether the request method is preserved. Older clients changed a POST into a GET on 301 and 302, which is why the newer 307 and 308 exist.
- 301 Moved Permanently: the URL has changed for good. Use it for domain moves, http to https and renamed pages. Search engines transfer the old address to the new one.
- 302 Found: a temporary move. The original URL stays the canonical one.
- 307 Temporary Redirect: like 302, but the method and body must be repeated unchanged.
- 308 Permanent Redirect: like 301, but the method and body must be preserved. Prefer it for permanent redirects of API endpoints that accept POST.
- 303 See Other: after a POST, send the browser to a GET page, which prevents a duplicate submit on refresh.
- 304 Not Modified: not really a redirect, but a cache answer, covered in the next section.
Caching and 304 Not Modified
A server can tag a response with an ETag, or a Last-Modified date. The browser stores it and, later, asks whether its copy is still valid by sending If-None-Match or If-Modified-Since. If nothing changed, the server replies 304 with no body, which saves bandwidth while still confirming freshness.
# First request
HTTP/1.1 200 OK
ETag: "v42"
Cache-Control: max-age=0, must-revalidate
# Revalidation
GET /app.css
If-None-Match: "v42"
HTTP/1.1 304 Not ModifiedCache-Control: max-age=31536000, immutable is the right header for fingerprinted files, whose name changes when the content does. For HTML pages, a short or zero max-age with revalidation keeps content fresh. A 304 must not include a body and should repeat the caching headers.
4xx: client errors
Choose the most specific code, and return a body that tells the caller what to fix. APIs commonly send JSON with a machine-readable code and a human message.
- 400 Bad Request: the request is malformed, such as invalid JSON or a missing required parameter.
- 401 Unauthorized: despite the name, it means not authenticated. The credentials are missing or invalid, and the response should carry a WWW-Authenticate header.
- 403 Forbidden: the caller is identified but not permitted. Logging in again will not help.
- 404 Not Found: no resource at this URL. Some sites return 404 instead of 403 to avoid revealing that a private resource exists.
- 405 Method Not Allowed: the URL exists but not for this method, and the Allow header lists the valid ones.
- 409 Conflict: the request clashes with the current state, such as a duplicate email or an edit based on an outdated version.
- 410 Gone: the resource was removed on purpose and will not return. Search engines tend to drop these URLs faster than 404s.
- 422 Unprocessable Content: the JSON was valid but failed validation rules. Many APIs use 400 for this too, so pick one convention and document it.
- 429 Too Many Requests: rate limit reached. Add Retry-After so clients know how long to wait.
5xx: server errors
- 500 Internal Server Error: an unexpected failure in your code. Log the details, and show the user a generic message rather than a stack trace.
- 501 Not Implemented: the server does not support the requested method at all.
- 502 Bad Gateway: a proxy or gateway received an invalid response from the upstream application. Typical causes are a crashed app process or a wrong upstream port.
- 503 Service Unavailable: the server is overloaded or down for maintenance. Send Retry-After, and use 503 for planned downtime so search engines do not treat the pages as gone.
- 504 Gateway Timeout: the proxy waited too long for the upstream. Look for slow database queries or external calls that exceed the proxy timeout.
When you see 502 or 504, the failing part is behind the front-end server, so read the application log, not the web server log alone.
SEO implications
- Use 301 or 308 when a page moves permanently, and point the old URL straight to the final one. Chains of redirects waste crawl time and slow users.
- Avoid using 302 for a move you intend to keep; the old URL may stay in results.
- A soft 404 is a page that says 'not found' but returns 200. Search engines flag these, so a missing page should return a real 404 or 410, along with a helpful custom error page.
- Do not redirect every missing URL to the home page; it is treated like a soft 404 and confuses visitors.
- Return 503 with Retry-After during maintenance, not 200 with a notice.
- Check that robots-blocked or noindex pages return the intended code, because a 200 with the wrong tags is a common launch mistake.
Debugging with curl
curl shows exactly what the server sent, without a browser cache or extensions in the way. The -I flag sends a HEAD request and prints only the headers, -L follows redirects, and -v shows the whole exchange.
curl -I https://example.com/old-page # status and headers
curl -IL https://example.com/old-page # follow the redirect chain
curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" https://example.com/old-page
curl -I -H "If-None-Match: \"v42\"" https://example.com/app.css # test for 304Some servers answer HEAD differently from GET, so if the result looks wrong, repeat with curl -s -D - -o /dev/null <url>, which sends a GET and prints the headers. The Network tab in browser developer tools shows the same codes for each request on a page.
Keep reading
- Web developmentTechnical SEO Checklist for a New WebsiteTechnical SEO makes sure search engines can find, read and index your pages. Check crawlability, indexability, page titles, headings, internal links, structured data and mobile speed, confirm the result in Search Console, and accept that new domains take time to appear.
- Interview questions and cheat sheetsGit Commands Cheat Sheet by TaskThis Git cheat sheet is organised by what you are trying to do, with copy-ready commands and a clear label on every command that can destroy work. It ends with the reflog, which is how most lost commits get back.
- Interview questions and cheat sheetsSQL Cheat Sheet for BeginnersThis cheat sheet teaches the SQL you use every week, task by task, with every query written against one small customers and orders schema. It uses standard SQL and points out where MySQL, PostgreSQL, SQL Server and SQLite differ.
- Web developmentHow to Speed Up a Next.js WebsiteMost slow Next.js sites are slow for ordinary reasons: oversized images, late-loading fonts, too much client-side JavaScript and uncached data. Fix those four in order, and measure with both Lighthouse and real-user data so you know the change helped.
Need this built properly for your business?
CodingMarble is a remote studio in India that builds websites, apps and games on fixed packages with the scope written down before payment. Try the free tools we run, or start a project when you are ready.