Lesson 6 of 18
3. Client and Server

3.5 What do status codes tell you?

3 min read+10 XP

In the restaurant: The waiter's reply tells you what happened: "here you go", "we moved, it's at the other branch", "that's not on the menu", or "sorry, the kitchen is on fire".

In the system: Every response starts with a three-digit status code. The first digit tells you the family:

FamilyMeaningCommon ones
2xxIt worked200 OK, 201 Created, 204 No Content
3xxLook somewhere else301 Moved Permanently, 302 Found, 304 Not Modified (your cached copy is still good)
4xxThe client made a mistake400 Bad Request, 401 Unauthorized (who are you?), 403 Forbidden (I know who you are; you can't), 404 Not Found, 409 Conflict, 429 Too Many Requests
5xxThe server failed500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout

Pairs that trip people up:

  • 401 vs 403: 401 means "you haven't proved who you are" (log in). 403 means "I know who you are, and you're not allowed".
  • 502 vs 504: both come from something in the middle, like a load balancer. 502: the server behind it sent back a bad or broken response. 504: the server behind it didn't answer in time.
  • 503: the server is overloaded or down for maintenance, and it's saying so.

Why it matters for design: clients and load balancers act on these codes. A 5xx may be worth retrying; a 4xx usually isn't, because sending the same bad request again gets the same answer.

Memory code: "2 is good, 3 go elsewhere, 4 your fault, 5 our fault."