DevKit
← Back to Blog

HTTP Status Codes Guide: What Each Code Really Means

8 min read

Every HTTP response carries a three-digit status code, and that number is the server telling the client how things went in one glance. Returning the right one makes an API predictable: clients, caches, and browsers all change behavior based on it. Returning the wrong one causes bugs that are maddening to trace, because the body says one thing and the status says another.

This guide walks through the five classes, the codes that actually come up, and the pairs people mix up most.

The five classes

The first digit groups every code into a class:

That 4xx vs 5xx split is the one to internalize. A 4xx says the problem is on the caller side, a 5xx says the problem is on yours. Returning a 500 for bad user input, or a 400 for a crashed database, sends monitoring and clients down the wrong path.

Success codes

Redirection codes

Client error codes

Server error codes

401 vs 403, the pair everyone confuses

These two sound similar and are routinely swapped. The distinction is about identity versus permission.

Return 401 when the server does not know who the caller is: no token, an expired token, or bad credentials. The implied message is authenticate and try again. Return 403 when the caller is authenticated but lacks rights for this action: a logged-in user hitting an admin-only endpoint. The implied message is you are known, and you still cannot do this.

A quick test: would logging in with different credentials fix it? If yes, it is 401. If the user is already correctly logged in and simply lacks permission, it is 403.

301 vs 302, the other common mix-up

The difference is permanence, and it has real consequences. A 301 tells clients and search engines the move is permanent. They cache it hard and update bookmarks and indexes, so reverting later is painful because clients keep following the old redirect from cache.

A 302 says the move is temporary, so clients keep requesting the original URL. Reach for 302 during maintenance pages, A/B tests, or any redirect you intend to remove. Use 301 only when you are confident the change is forever, such as a retired domain. Using 301 by accident for a temporary redirect is a frequent and hard-to-undo mistake.

Choosing the right code

A short mental checklist covers most cases. Did it succeed with data? 200. Did it create something? 201. Succeed with nothing to return? 204. Is the caller unauthenticated? 401. Authenticated but not allowed? 403. Does the resource not exist? 404. Did validation fail? 422. Did your code break? 500. Getting these right turns your API responses into an accurate signal instead of a guessing game.

Related tools: