A Beginner's Guide to HTTP/HTTPS Status Codes: Understanding Web Responses

A Beginner's Guide to HTTP/HTTPS Status Codes: Understanding Web Responses

If you’ve ever tried to open a website and saw a message like “404 Not Found” or “500 Internal Server Error,” you’ve encountered HTTP or HTTPS status codes. These codes help explain what’s happening behind the scenes when you interact with websites. For someone new to web development or networking, it’s important to know what these codes mean and how they work. Don’t worry—it’s easier than it sounds!

In this blog, I’ll walk you through the basics of HTTP/HTTPS status codes, explaining them in simple terms, with examples to help you understand when they happen and why they matter.

What Are HTTP and HTTPS Status Codes?

HTTP (Hypertext Transfer Protocol) and HTTPS (HTTP Secure) are the protocols used by web browsers and servers to communicate. Every time you try to load a webpage or submit a form, your browser sends a request to the server. The server then responds with data like the HTML code of the webpage, and also sends back a status code.

Status codes are like tiny messages that tell you what happened with your request. Was it successful? Was there a problem? Should you try something else? These codes help answer these questions.

Types of Status Codes

Status codes are grouped into five different categories, based on the first number of the code. Let’s break them down:

  1. 1xx: Informational Codes

These codes are rarely seen, but they tell you that the server received the request and it’s still processing it.

  • 100 Continue

This code means the server has received the request headers, and the client (your browser) can continue sending the rest of the information, like the body of the message.

HTTP/1.1 100 Continue

Example:
Imagine you're uploading a large file. The server tells you, "Got the start of your request, keep going."

  • 101 Switching Protocols

The server is changing the protocol, as requested by the client.

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade

Example Scenario:
A client requests the server to switch from HTTP to WebSockets for better two-way communication.

  1. 2xx: Success Codes

These codes mean everything went well, and the server successfully processed the request.

  • 200 OK

This is the best news! It means everything went smoothly, and the server returned the requested information.

HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8

Example:
You type in the URL for your favorite website, and it loads perfectly. Behind the scenes, the server sends a 200 OK to your browser, which means “Here’s the webpage you asked for!”

  • 201 Created

This code shows that something new was created as a result of the request.

HTTP/1.1 201 Created
Location: /users/12345

Example:
You sign up for an account on a website, and after clicking "submit," the server creates your new account and sends back a 201 Created message.

  • 204 No Content

This code means the server successfully processed the request, but there’s no new data to send back.

HTTP/1.1 204 No Content

Example: You update your profile settings, but the page doesn’t need to reload. The server says, "Got it, but there’s no need to show anything new," with a 204 No Content.

  1. 3xx: Redirection Codes

Redirection status codes mean that the client (your browser) needs to take extra steps to find the resource you requested.

  • 301 Moved Permanently

The page you’re looking for has moved to a new permanent address. The server tells your browser, “Go here instead.”

HTTP/1.1 301 Moved Permanently
Location: https://www.newwebsite.com

Example: A company changes its website domain from oldwebsite.com to newwebsite.com. When you try to visit the old website, you’ll be redirected permanently with a 301 Moved Permanently.

  • 302 Found

This is similar to 301, but it means the move is temporary. The page will come back to the original URL later.

HTTP/1.1 302 Found
Location: https://www.site.com/maintenance

Example:
A website is undergoing maintenance, so you are temporarily redirected to a different page until the maintenance is complete.

  • 304 Not Modified

This code tells the browser that the requested page hasn’t changed since the last time you visited, so it’s okay to use the cached (stored) version of the page from your device.

HTTP/1.1 304 Not Modified

Example:
You reload a webpage, but nothing on the server has changed since your last visit, so the server sends a 304 Not Modified to save time and bandwidth.

  1. 4xx: Client Error Codes

These codes mean something went wrong with the request, usually because of a mistake made by the client (your browser or you).

  • 400 Bad Request

The server couldn’t understand your request because of bad syntax or invalid data.

HTTP/1.1 400 Bad Request
Content-Type: application/json
{
  "error": "Invalid format."
}

Example:
You try to submit a form, but you forgot to fill out a required field. The server sends back a 400 Bad Request error, saying, "I don’t understand what you’re trying to do."

  • 401 Unauthorized

This code means you need to log in or provide valid credentials to access the page.

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="Access to site"

Example:
You try to visit a members-only section of a website without logging in, and the server responds with a 401 Unauthorized to remind you to sign in.

  • 403 Forbidden

Even though the server understood your request, you don’t have permission to access the resource.

HTTP/1.1 403 Forbidden
Content-Type: text/html
{
  "error": "Access denied."
}

Example:
You try to access an admin page without the proper privileges. The server knows who you are but sends back a 403 Forbidden saying, "You don’t have permission."

  • 404 Not Found

This is one of the most famous codes! It means the page you’re looking for can’t be found on the server.

HTTP/1.1 404 Not Found
Content-Type: text/html
{
  "error": "Page not found."
}

Example:
You type in the URL of a page that doesn’t exist (maybe because it was deleted or you made a typo), and you get a 404 Not Found error.

  1. 5xx: Server Error Codes

These codes mean the server encountered a problem and couldn’t complete your request.

  • 500 Internal Server Error

Something went wrong on the server’s side, but it’s not exactly clear what.

HTTP/1.1 500 Internal Server Error
Content-Type: application/json
{
  "error": "Something went wrong."
}

Example:
You try to load a webpage, but the server crashes due to a bug in its code, so it sends you a 500 Internal Server Error.

  • 502 Bad Gateway

This happens when a server (often acting as a gateway or proxy) gets an invalid response from another server.

HTTP/1.1 502 Bad Gateway
Content-Type: text/html
{
  "error": "server error."
}

Example:
You visit a website that’s using a proxy server, but the server it’s trying to reach is down. The proxy server returns a 502 Bad Gateway error.

  • 503 Service Unavailable

The server is temporarily unavailable, often due to maintenance or being overloaded.

HTTP/1.1 503 Service Unavailable
Retry-After: 3600

Example:
A website is swamped with too many visitors or undergoing updates, so it responds with a 503 Service Unavailable, telling you to come back later.

  • 504 Gateway Timeout

This code appears when one server acting as a gateway doesn’t receive a timely response from another server.

HTTP/1.1 504 Gateway Timeout
Content-Type: text/html
{
  "error": "The server took too long to respond."
}

Example:
You request a page, but the upstream server takes too long to respond. The gateway times out and sends you a 504 Gateway Timeout.

Conclusion

HTTP and HTTPS status codes are like traffic signals for the web—they tell you what’s happening between your browser and the server. While they might seem complex at first, they’re actually really helpful for diagnosing problems and understanding how web applications work. As you continue learning about web development, understanding these codes will make debugging much easier and improve your skills as a developer.

Happy coding!

Reference: