completefrontend

What are HTTP status codes?

HTTP status codes are the three-digit numbers a server sends back to say how a request went. Here are the five groups, the codes you'll actually meet, and what to do when you see each one.

Four status codes as colored tiles: 200 OK, 301 Moved Permanently, 404 Not Found, and 503 Service Unavailable

When you call a phone number, you can tell what happened within seconds. The call connects, or a recording says the number has changed. Or it says the number doesn't exist, or that all lines are busy. You know how it went before anyone says hello. A web server tells your browser the same kind of thing, with a number.

HTTP status codes are three-digit numbers that a server puts at the start of every response to say how a request went. HTTP is the set of rules browsers and servers use to talk. The first digit gives the group: 2xx means it worked, 3xx means look somewhere else, 4xx means the request had a problem, and 5xx means the server failed.

Codes starting with 1 are early "keep going" notes that you'll rarely see.

Where do you see a status code?

Every time your browser loads a page, an image, or some data, the server answers with a status code first. Here's the start of a real response:

HTTP/1.1 404 Not Found
Content-Type: text/html

The first line holds the code, 404, and a short name for it, Not Found. The name is for people. Programs read the number. The second line is a header, an extra piece of information about the response. This one says the body is an HTML page.

To see them, open your browser's developer tools, pick the Network tab, and reload the page. The Status column shows the code for every file the page loaded. Seeing every request in the Network panel tours the rest of that tab.

What are the five groups of HTTP status codes?

Codes Group What it means
100 to 199 Informational "Got it so far, keep going."
200 to 299 Success "It worked."
300 to 399 Redirection "What you want is somewhere else."
400 to 499 Client error "Something's wrong with your request."
500 to 599 Server error "The server couldn't handle it."

The client is the program that sent the request, like your browser or your app. So a 4xx code points at the request, and a 5xx code points at the server. That split tells you where to start looking when something breaks.

The five groups of HTTP status codes by first digit, 1xx informational, 2xx success, 3xx redirection, 4xx client error, and 5xx server error, each with common examples
The first digit tells you which group a code is in

Which status codes will you actually meet?

These are the codes you'll meet most while learning.

Code Name What it means What to do
200 OK The request worked, and the answer is in the body. Use the data.
201 Created The request worked and made something new, usually after a POST. Show that it was saved.
204 No Content The request worked, and there's nothing to send back. Don't try to read a body.
301 Moved Permanently The address has changed for good. The new one is in the Location header. Update your links to the new address.
302 Found The address has moved for now. Keep using the old one. Nothing. The browser follows it for you.
304 Not Modified Your saved copy is still up to date. Nothing. The browser uses its copy.
400 Bad Request The server couldn't understand the request, like data in the wrong format. Check what you sent.
401 Unauthorized The server doesn't know who you are. Log in, or send your login token.
403 Forbidden The server knows who you are, but you aren't allowed. Ask for access.
404 Not Found The server can't find what you asked for. Check the address for typos.
429 Too Many Requests You sent too many requests in a short time. Wait, then try again more slowly.
500 Internal Server Error Something went wrong on the server. Try again later.
503 Service Unavailable The server can't handle requests right now, often because it's overloaded or down for maintenance. Wait and try again later.

A 304 is about the cache, the saved copies of files a browser keeps so it doesn't download them twice. The browser asks whether its copy is still current, and 304 means yes. HTTP caching explains how that conversation works.

What is the difference between 401 and 403?

Both mean you can't have the page, but for different reasons. A 401 means the server doesn't know who you are yet. Proving who you are is called authentication, so 401 really means "not authenticated". Logging in usually fixes it.

A 403 means the server knows exactly who you are, and the answer is still no. Your account just doesn't have permission. Logging in again won't change anything.

Some servers send 404 instead of 403 on purpose. That way, a stranger can't even tell the page exists.

What is the difference between 301 and 302?

A 301 says the page has moved for good. Browsers go to the new address in the Location header, and search engines move the old page's ranking to it. Use it when you rename a page or move to a new domain.

A 302 says the move is only for now, so the old address stays the one to use. Two related codes, 307 and 308, work like 302 and 301, with one extra promise: they never change the request's method. Redirects explains why every redirect also costs time.

Does a 404 error mean the site is down?

No. A 404 means the server is up and answered you. It just couldn't find that page. If the whole site were down, you'd get a 5xx code, or no answer at all. Then the browser shows its own error page.

A 5xx code means the request reached a server, but the server couldn't finish the job. If the server is yours, its logs will say what went wrong. If it isn't, waiting and trying again is the usual move. A 503 or 429 response can include a Retry-After header that says how long to wait.

How do you check a status code in JavaScript?

When you call an API with fetch, the response has a status property with the code. It also has an ok property that's true for any code from 200 to 299.

const response = await fetch("/api/orders/42");

if (!response.ok) {
  throw new Error(`Request failed with status ${response.status}`);
}

const order = await response.json();

The if stops the code when the server answers with an error, like 404 or 500. Without it, the code would carry on and treat the error response as if it were the order.

This check matters because fetch doesn't fail on error codes. It only fails when no response arrives at all, like when you're offline. Why fetch doesn't reject on HTTP errors walks through it. The fetch lesson covers response.ok and status with live examples.

What mistakes do beginners make with status codes?

  • Sending 200 for everything. Some APIs answer 200 even when something failed, with the error hidden in the body. Then every tool that reads the code thinks it worked. Send the code that matches what happened.
  • Treating every 4xx the same. A 401 needs a login screen, a 404 needs a "not found" message, and a 429 needs a pause. Each one deserves its own reaction in your app.
  • Retrying a 400 straight away. The same request will fail the same way. Retries make sense for 429 and some 5xx codes, with a longer wait between each try. Retries and backoff shows how.
  • Reading the body of a 204. There's no body, so response.json() throws an error.

If you design APIs, API contracts and errors shows how to pick codes and shape error responses a frontend can rely on.

Where should you go next?

If requests and responses are still new, start with what is an API. Then work through the fetch lesson and its error handling. To practice retrying the right failures, solve the retry with backoff problem. And to see how a Next.js page sends 404, 401, and 403, read not-found and access errors.

Written by Shrikanth PS

Senior Software Engineer at Microsoft, working on Copilot Enterprise, with more than nine years in frontend engineering.