404

HTTP 404 Not Found

4xx Client Error

4xx Client Error RFC 7231, Section 6.5.4

What is HTTP 404 Not Found?

The 404 (Not Found) status code is one of the most recognized HTTP status codes. It indicates that the server cannot find the requested resource. In a browser, this means the URL is not recognized. In an API, this can mean the endpoint is valid but the specific resource doesn't exist. The server may return a custom 404 page that helps users navigate back to a working page.

Common Use Cases

  • Broken links on websites
  • Deleted or moved pages without redirect
  • API requests for non-existent resources
  • User mistyping a URL

Usage Example

When a user requests /users/999 and no user with that ID exists, return 404 Not Found with a clear message. For web pages, provide a custom 404 page with navigation links to help users find what they are looking for. For APIs, return a structured error with the resource type and identifier.

// Laravel - model not found (automatically returns 404)
$user = User::findOrFail($id);

// Manual 404
if (! $user) {
    return response()->json([
        'error' => 'User not found',
        'user_id' => $id,
    ], 404);
}

Common Mistakes

⚠️

Mistake: Returning 404 for API endpoints that do exist but return empty results

Fix: If an endpoint exists but returns no results (e.g., an empty list), return 200 OK with an empty array, not 404. 404 means the resource or endpoint itself was not found.

⚠️

Mistake: Not distinguishing between missing resource and wrong endpoint

Fix: If the URL path itself is invalid (no matching route), return 404 with a message like "Endpoint not found". If the path is valid but the specific resource ID does not exist, return 404 with a message like "User with ID 999 not found".

⚠️

Mistake: Leaking sensitive information in 404 pages

Fix: Custom 404 pages should not reveal server paths, technology stack, or internal details that could aid attackers. A simple, branded page is sufficient.

Last updated: 21 Jun 2026