Skip to content

The most important HTTP status codes

HTTP Status Codes - Cover

When I just started surfing yeeeears ago I started tinkering with websites, trying to manipulate them into giving me the good old 404 error, often delivered with a funny (or even nasty) static HTML document.

HTTPS Status Codes - Not Found 404
HTTPS Status Codes – Not Found 404

Little did I know that the number 404 is just one of many that the server returns to the client. The number itself is just one component of a response that gives us additional information about the status of the request.

So, I’ve decided to write a quick blog post that will mention some of the most commonly used HTTP status codes, explain their purpose and use cases. Additionally, at the end of the article I’ve linked a site that has a list of all possible HTTP status codes if you want to analyze them in more detail.

So, without further ado – let us begin!

First of all, what the heck is HTTP?

Before we even mention HTTP status codes, let us step back for a second and just touch upon HTTP itself.

HTTP (Hypertext Transfer Protocol) is the communication protocol on which the web is based around. It is just a form of communication, with its own rules, models and mechanisms to handle the communication between the client and the server. In layman’s terms, the communcation can be explained like this: the client machine makes a HTTP request to a server machine, and the server responds with with a resource that the client requested or some erronous state.

HTTP is a stateless form of communication. Requests on their own are individual and separate from each other, and every message exchange lives and happens completely independent from every other one.

HTTP requests are requests that the client extends to the server. They must include an URL, a HTTP method, one or more headers and some optional parameters such as the request body.(keep in mind this explanation is extremely banal and incomplete, but this is enough for start. I might be writing another article on HTTP in more detail sometimes in the future).

Client and Server communicate through the internet
A really simple visual representation of how a client and a server communicate.

Ok, HTTP is a pattern form communication, so – what are HTTP status codes then?

HTTP status codes are just three-digit responses to the client’s requests.

Lets say we sent an HTTP request to a server, and we wait for a response. That response can be anything, a number, a sentence, some complex object, or even an error message. We can receive anything, and we can make sense of how the communication goes based on the response (well, if we get an error, we know that something went awry). But knowing the real status of the communication can be simply determined by HTTP status code. A HTTP status code tells us the state of the request. Each code has a certain meaning to the client. We get a response from the server, but if we also get 404 as a response code then we can determine that something went wrong along the way.

I think I’m getting this, so what are the most important HTTP status codes?

Before we can even start picking up some of the most commonly used status codes there is something important to note. Each of those HTTP status codes belongs to a certain subclass depending on the status of the request itself. With this in mind we divide HTTP status codes into five different categories or classes.

  • 1xx or Informational – They indicate provisional responses, and they give more data to the client about the request in motion. They might inform the client that the request will take a significant time to complete, or that it will switch protocols, or that the initial part of the request has been received but not rejected by the server (the request limbo). They are rarely used so I won’t mention them more.
  • 2xx or Success status codes simply indicate that the request was successfully received, understood and accepted.
  • 3xx or Redirection status codes indicate that additional action need to be taken in order to fullfill the request. They are most commonly found during redirections and forwarding.
  • 4xx or Client Error status codes most commonly indicate a problem with the user’s request, and not within the server. 4xx status codes will stop exchange of resources between client and the server, and they can be fixed by either modifying the request itself or changing it.
  • 5xx or Server Error indicate that the server has received the request but is unable to perform the request.

Let us now explain the 5 most commonly used HTTP status codes.

  • 200 OK – Basically you can sleep without worry. Everything went according to plan, and your request executed exactly as it should. Amazing!
  • 400 Bad Request – The server can’t (or won’t) process the request due to an error in the client (request syntax being invalid, invalid framing or deceptive request routing). We get this error code as a default response code in case a more specific error code isn’t found.
  • 404 Not Found – The most common status code in existence today, and it is sent when a resource requested by the client doesn’t exist or the server doesn’t want that the client knows that it exists. Wanna see an example – click https://thedukh.com/doesnt-work.
  • 500 Internal Server Error server side error that usually says that some kind of bug appeared on the server. If you encounter this response, you can rest assured that it most probably isn’t your fault (unless you’re also writing backend code, in which case it 100% is your fault). 500 is a good generic error code to chose if no other codes are applicable.
  • 503 Service Unavailable – usually sent by the server when the server is incapable of handling the request, maybe the server is overloaded, just booting up, or some part of the application required isnt available. The server can trigger a Retry-After to run the call again if this status code comes back as a response.
Google 400 error screenshot.
That’s a nasty one!

Finishing words

The above mentioned HTTP status codes only scratch the surface of the number of possible variations that are available. And even if you’ll never use every status code, it is still good to know at least what each subclass is doing and a some of the codes in each subclass. A common tech trivia question hides behind one of the status codes.

For more detailed information about status codes, and a full list of all available ones please check this site – https://httpstatuses.com/.

Additionally if you liked this article, click here to check out more.