HTTP Error Codes Explained with Examples

Reading Time: 10 mins

Introduction

Ever clicked on a website link only to see โ€œ404 Not Foundโ€ or โ€œ500 Internal Server Errorโ€? These cryptic messages are HTTP error codes, and understanding them is crucial for anyone working with websites or web applications. Whether youโ€™re a beginner learning web development or an experienced developer troubleshooting issues, this comprehensive guide will demystify every HTTP status code you need to know.

HTTP error codes are like a universal language between web browsers and servers. When something goes wrongโ€”or rightโ€”these three-digit numbers tell us exactly what happened. But hereโ€™s the problem: most people see these codes and panic, not knowing whether itโ€™s something they can fix or if they need to contact technical support.

In this complete guide, youโ€™ll learn what every major HTTP error code means, see real-world examples of when they occur, and discover how to fix the most common issues. By the end, youโ€™ll be able to diagnose web problems like a pro and implement proper error handling in your own projects.


What Are HTTP Error Codes?

HTTP error codes are three-digit numbers that web servers send to browsers to indicate the status of a web request. These codes are part of the Hypertext Transfer Protocol (HTTP), which governs how data is transferred between web browsers and servers.

Every time you visit a website, your browser sends an HTTP request to the server hosting that site. The server processes this request and responds with an HTTP status code along with the requested content (or an error message).

The Structure of HTTP Status Codes

HTTP status codes follow a specific pattern:

  • First digit: Indicates the general category of response
  • Last two digits: Provide specific information about the response
  • Range: 100-599 (though not all numbers are used)

Why HTTP Error Codes Matter

Understanding HTTP error codes is essential for several reasons:

For Website Owners

  • Identify and fix broken links quickly
  • Improve user experience by handling errors gracefully
  • Monitor website health and performance
  • Optimize SEO by resolving crawl errors

For Developers

  • Debug web applications effectively
  • Implement proper error handling
  • Create better user interfaces
  • Troubleshoot API integrations

For Users

  • Understand what went wrong when websites fail
  • Know whether to try again or report issues
  • Distinguish between temporary and permanent problems

HTTP vs HTTPS Error Codes

The same error codes apply to both HTTP and HTTPS connections. The only difference is that HTTPS adds an encryption layer for security, but the status code system remains identical.


How HTTP Status Codes Work

To understand HTTP error codes, letโ€™s look at how web communication works. Think of it like ordering food at a restaurantโ€”you make a request, and the kitchen (server) responds with a status update.

The Request-Response Cycle

  1. Browser Request: Your browser asks the server for a specific resource
  2. Server Processing: The server attempts to fulfill the request
  3. Status Code Response: The server sends back a status code indicating success or failure
  4. Content Delivery: If successful, the server also sends the requested content

Status Code Categories

HTTP status codes are organized into five main categories:

1xx โ€“ Informational Responses

  • The request was received and is being processed
  • Rarely seen by end users
  • Used for protocol-level communication

2xx โ€“ Success Responses

  • The request was successfully received and processed
  • Most common: 200 OK
  • Indicates everything worked as expected

3xx โ€“ Redirection Responses

  • Additional action needs to be taken to complete the request
  • Usually involves redirecting to a different URL
  • Common for moved content or URL changes

4xx โ€“ Client Error Responses

  • The request contains an error or cannot be fulfilled
  • Problem is on the user/browser side
  • Most familiar to regular internet users

5xx โ€“ Server Error Responses

  • The server failed to fulfill a valid request
  • Problem is on the server side
  • Indicates technical issues with the website

1xx Informational Status Codes

Informational status codes indicate that the request has been received and the process is continuing. These codes are rarely seen by end users but are important for developers working with APIs and web applications.

100 Continue

Meaning: The server has received the request headers and the client should proceed to send the request body.

When it occurs: Used with large file uploads where the client wants to check if the server will accept the request before sending data.

Example scenario: Uploading a large video file to a content management system.

HTTP
HTTP/1.1 100 Continue

101 Switching Protocols

Meaning: The server is switching to a different protocol as requested by the client.

When it occurs: Most commonly seen when upgrading from HTTP to WebSocket connections.

Example scenario: Real-time chat applications that need persistent connections.

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

102 Processing (WebDAV)

Meaning: The server has received and is processing the request, but no response is available yet.

When it occurs: Used in WebDAV operations that might take a long time to complete.

Example scenario: Bulk file operations on cloud storage systems.


2xx Success Status Codes

Success status codes indicate that the clientโ€™s request was successfully received, understood, and accepted. These are the codes you want to see when everything is working correctly.

200 OK

Meaning: The request was successful and the server returned the requested resource.

When it occurs: This is the standard response for successful HTTP requests.

Example scenario: Successfully loading a webpage, submitting a form, or fetching data from an API.

HTTP
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1234

201 Created

Meaning: The request was successful and a new resource was created as a result.

When it occurs: Typically used after POST requests that create new data.

Example scenario: Successfully creating a new user account or posting a new blog article.

HTTP
HTTP/1.1 201 Created
Location: /users/12345
Content-Type: application/json

202 Accepted

Meaning: The request has been accepted but processing is not complete.

When it occurs: Used for asynchronous operations that will be processed later.

Example scenario: Submitting a large file for processing or queuing a background task.

204 No Content

Meaning: The request was successful but thereโ€™s no content to return.

When it occurs: Common with DELETE operations or when updating data without returning anything.

Example scenario: Successfully deleting a file or updating user preferences.


3xx Redirection Status Codes

Redirection status codes indicate that further action needs to be taken by the client to complete the request. These codes help manage content that has moved or changed location.

301 Moved Permanently

Meaning: The requested resource has been permanently moved to a new URL.

When it occurs: Used when content has permanently moved to a new location.

Example scenario: A website changes its domain name or restructures its URL system.

SEO Impact: Passes most of the original pageโ€™s SEO value to the new URL.

HTTP
HTTP/1.1 301 Moved Permanently
Location: https://example.com/new-page

302 Found (Temporary Redirect)

Meaning: The resource temporarily resides at a different URL.

When it occurs: Used for temporary redirects where the original URL should still be used.

Example scenario: Redirecting users during website maintenance or A/B testing.

SEO Impact: Does not pass SEO value to the new URL.

304 Not Modified

Meaning: The resource hasnโ€™t been modified since the last request.

When it occurs: Used with caching mechanisms to improve performance.

Example scenario: Browser checks if a cached image is still current.

HTTP
HTTP/1.1 304 Not Modified
Cache-Control: max-age=3600

307 Temporary Redirect

Meaning: Similar to 302 but guarantees that the request method wonโ€™t change.

When it occurs: Used when you need to preserve the original HTTP method (GET, POST, etc.).

Example scenario: Temporarily redirecting a POST request while maintaining the POST method.

308 Permanent Redirect

Meaning: Similar to 301 but guarantees that the request method wonโ€™t change.

When it occurs: Used for permanent redirects while preserving the HTTP method.

Example scenario: Permanently moving an API endpoint while maintaining POST requests.


4xx Client Error Codes (Most Common)

Client error codes indicate that the request contains an error or cannot be fulfilled due to a problem on the client side. These are the errors most commonly encountered by website visitors.

400 Bad Request

Meaning: The server cannot process the request due to invalid syntax or malformed request.

When it occurs:

  • Malformed URLs
  • Invalid JSON in API requests
  • Missing required parameters

Example scenario: Submitting a form with invalid data format.

How to fix: Check request syntax, validate form data, and ensure proper encoding.

HTTP
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
  "error": "Invalid email format"
}

401 Unauthorized

Meaning: Authentication is required and has failed or has not been provided.

When it occurs:

  • Accessing protected content without logging in
  • Invalid login credentials
  • Expired authentication tokens

Example scenario: Trying to access your bank account with wrong password.

How to fix: Provide valid authentication credentials or log in properly.

403 Forbidden

Meaning: The server understood the request but refuses to authorize it.

When it occurs:

  • Insufficient permissions
  • IP address blocking
  • Resource access restrictions

Example scenario: Trying to access admin pages as a regular user.

How to fix: Contact the website administrator or check if you have proper permissions.

404 Not Found

Meaning: The server cannot find the requested resource.

When it occurs:

  • Broken links
  • Deleted pages
  • Mistyped URLs
  • Website restructuring

Example scenario: Clicking on an old bookmark to a page that no longer exists.

How to fix:

  • Check the URL for typos
  • Use the websiteโ€™s search function
  • Navigate from the homepage
  • Contact the website owner about broken links
HTTP
HTTP/1.1 404 Not Found
Content-Type: text/html

<h1>Page Not Found</h1>
<p>The requested page could not be found.</p>

405 Method Not Allowed

Meaning: The request method is not supported for the requested resource.

When it occurs: Using wrong HTTP method (e.g., POST instead of GET).

Example scenario: Trying to POST data to an endpoint that only accepts GET requests.

How to fix: Use the correct HTTP method as specified in the API documentation.

408 Request Timeout

Meaning: The server timed out waiting for the request.

When it occurs: Slow internet connections or large file uploads.

Example scenario: Uploading a large video file over a slow connection.

How to fix: Try again with a faster internet connection or smaller files.

409 Conflict

Meaning: The request conflicts with the current state of the server.

When it occurs: Data conflicts during updates or resource conflicts.

Example scenario: Trying to create a user account with an email that already exists.

How to fix: Resolve the conflict by updating conflicting data or choosing different values.

410 Gone

Meaning: The resource was available previously but is no longer available and will not be available again.

When it occurs: Permanently removed content.

Example scenario: A discontinued product page that wonโ€™t be coming back.

How to fix: The content is permanently gone; look for alternatives.

429 Too Many Requests

Meaning: The user has sent too many requests in a given time period (rate limiting).

When it occurs: API rate limiting or spam protection.

Example scenario: Making too many API calls in a short time period.

How to fix: Wait before making more requests or implement proper rate limiting in your code.


5xx Server Error Codes

Server error codes indicate that the server failed to fulfill a valid request. These errors are typically temporary and indicate problems with the websiteโ€™s infrastructure.

500 Internal Server Error

Meaning: A generic error message when the server encounters an unexpected condition.

When it occurs:

  • Server configuration issues
  • Programming errors
  • Database connection problems
  • Resource exhaustion

Example scenario: A websiteโ€™s database server crashes during high traffic.

How to fix:

  • For users: Wait and try again later, or contact the website
  • For developers: Check server logs, review recent code changes, verify database connections
HTTP
HTTP/1.1 500 Internal Server Error
Content-Type: text/html

<h1>Something went wrong</h1>
<p>We're working to fix this issue. Please try again later.</p>

501 Not Implemented

Meaning: The server does not support the functionality required to fulfill the request.

When it occurs: Using HTTP methods or features not supported by the server.

Example scenario: Using a PATCH request on a server that doesnโ€™t support it.

How to fix: Use supported HTTP methods or upgrade the server software.

502 Bad Gateway

Meaning: The server, acting as a gateway, received an invalid response from an upstream server.

When it occurs:

  • Proxy server issues
  • Load balancer problems
  • Upstream server failures

Example scenario: A CDN cannot connect to the origin server.

How to fix:

  • For users: Try refreshing or wait for the issue to be resolved
  • For developers: Check proxy configurations and upstream server health

503 Service Unavailable

Meaning: The server is currently unavailable (overloaded or down for maintenance).

When it occurs:

  • Scheduled maintenance
  • Server overload
  • DDoS attacks
  • Resource exhaustion

Example scenario: A popular website experiencing unexpected traffic surge.

How to fix:

  • For users: Wait and try again later
  • For developers: Implement proper load balancing and scaling
HTTP
HTTP/1.1 503 Service Unavailable
Retry-After: 3600

<h1>Maintenance in Progress</h1>
<p>We'll be back shortly. Please try again in an hour.</p>

504 Gateway Timeout

Meaning: The server, acting as a gateway, did not receive a timely response from an upstream server.

When it occurs:

  • Slow upstream servers
  • Network connectivity issues
  • Long-running processes

Example scenario: A web application waiting too long for a database query to complete.

How to fix:

  • For users: Try again later
  • For developers: Optimize slow queries, increase timeout values, or implement caching

507 Insufficient Storage

Meaning: The server is unable to store the representation needed to complete the request.

When it occurs: Server running out of disk space.

Example scenario: Trying to upload files when the serverโ€™s storage is full.

How to fix: Free up server storage space or upgrade storage capacity.


How to Fix Common HTTP Errors

Understanding how to troubleshoot and fix HTTP errors is essential for maintaining a healthy website. Hereโ€™s a comprehensive guide to resolving the most common issues.

Fixing 404 Not Found Errors

Step 1: Identify Broken Links

  • Use tools like Google Search Console to find 404 errors
  • Check internal links regularly with tools like Screaming Frog
  • Monitor external links pointing to your site

Step 2: Implement Solutions

  • Set up 301 redirects for moved content
  • Fix broken internal links
  • Create custom 404 pages with helpful navigation
  • Update outdated content and remove dead links

Step 3: Prevention

  • Implement proper URL structure from the start
  • Use relative links when possible
  • Test links before publishing content
  • Set up monitoring for broken links
HTML
<!-- Custom 404 Page Example -->
<!DOCTYPE html>
<html>
<head>
    <title>Page Not Found</title>
</head>
<body>
    <h1>Oops! Page Not Found</h1>
    <p>The page you're looking for doesn't exist.</p>
    <a href="/">Return to Homepage</a>
    <form action="/search" method="get">
        <input type="text" name="q" placeholder="Search our site...">
        <button type="submit">Search</button>
    </form>
</body>
</html>

Fixing 500 Internal Server Errors

Step 1: Check Server Logs

  • Access error logs through your hosting control panel
  • Look for specific error messages and timestamps
  • Identify patterns in error occurrence

Step 2: Common Solutions

  • Review recent code changes and rollback if necessary
  • Check database connections and credentials
  • Verify file permissions (typically 644 for files, 755 for directories)
  • Increase server resource limits if needed

Step 3: Monitoring and Prevention

  • Implement error monitoring tools like Sentry or Rollbar
  • Set up automated backups and recovery procedures
  • Use staging environments for testing changes
  • Monitor server performance and resource usage

Fixing 403 Forbidden Errors

Step 1: Check File Permissions

  • Ensure proper file and directory permissions
  • Verify ownership of files and directories
  • Check for corrupted .htaccess files

Step 2: Server Configuration

  • Review web server configuration files
  • Check IP blocking rules and whitelist legitimate users
  • Verify SSL certificate configuration

Step 3: Content Management

  • Ensure proper user roles and permissions
  • Check for plugin or module conflicts
  • Review security plugin settings

General Troubleshooting Tips

For Website Owners

  1. Implement comprehensive error monitoring
  2. Create custom error pages for better user experience
  3. Set up proper redirects for moved content
  4. Regular website health checks and maintenance

For Developers

  1. Use proper error handling in code
  2. Implement logging for debugging purposes
  3. Test error scenarios during development
  4. Use HTTP status codes correctly in applications

For Users

  1. Clear browser cache and cookies
  2. Try accessing the site from a different device or network
  3. Check if the problem persists across different browsers
  4. Report persistent issues to website administrators

Best Practices for Handling HTTP Errors

Implementing proper error handling improves user experience and helps maintain website credibility. Here are the best practices for developers and website owners.

Custom Error Pages

Design Principles

  • Keep consistent branding and navigation
  • Provide helpful information about the error
  • Offer alternative actions (search, contact, navigation)
  • Include relevant internal links

Essential Elements

  • Clear, non-technical error explanation
  • Search functionality
  • Contact information
  • Link to homepage or main sections
  • Suggested content or popular pages

Error Monitoring and Logging

Implementation Strategy

  • Use tools like Google Search Console for SEO-related errors
  • Implement application performance monitoring (APM) tools
  • Set up automated error alerts for critical issues
  • Create error dashboards for team visibility

Key Metrics to Track

  • Error frequency and patterns
  • User impact and bounce rates
  • Resolution times
  • Error trends over time
JavaScript
// Example error handling in JavaScript
function handleApiError(error) {
    console.error('API Error:', error);
    
    switch(error.status) {
        case 401:
            // Redirect to login
            window.location.href = '/login';
            break;
        case 403:
            // Show permission error
            showErrorMessage('You don\'t have permission to access this resource.');
            break;
        case 404:
            // Show not found error
            showErrorMessage('The requested resource was not found.');
            break;
        case 500:
            // Show generic error
            showErrorMessage('Something went wrong. Please try again later.');
            break;
        default:
            showErrorMessage('An unexpected error occurred.');
    }
}

SEO Considerations

Impact on Search Rankings

  • 404 errors donโ€™t directly hurt SEO if handled properly
  • Too many 404s can indicate poor site maintenance
  • 301 redirects preserve SEO value when moving content
  • Custom error pages should not be indexed by search engines

Best Practices

  • Use proper HTTP status codes
  • Implement 301 redirects for moved content
  • Create helpful 404 pages that keep users on your site
  • Monitor and fix crawl errors in Google Search Console

User Experience Optimization

Progressive Enhancement

  • Provide fallback content for failed requests
  • Implement offline functionality where possible
  • Use loading states and error boundaries in single-page applications
  • Offer retry mechanisms for temporary failures

Communication Strategies

  • Use plain language instead of technical jargon
  • Provide estimated resolution times for known issues
  • Offer multiple contact methods for support
  • Show empathy and understanding in error messages

Frequently Asked Questions

What is the difference between 4xx and 5xx error codes?

4xx errors indicate client-side problems, meaning the issue is with the request being made (wrong URL, missing authentication, etc.). 5xx errors indicate server-side problems, meaning the server failed to fulfill a valid request due to internal issues.

Why do I keep getting 404 errors on my website?

Common causes of 404 errors include:

  • Broken internal or external links
  • Moved or deleted content without proper redirects
  • Mistyped URLs
  • Website restructuring without URL mapping
  • Server configuration issues

To fix this, audit your links regularly and implement proper redirects for moved content.

What should I do when I encounter a 500 Internal Server Error?

As a user:

  • Wait a few minutes and try again
  • Clear your browser cache
  • Try accessing from a different device or network
  • Contact the website administrator if the problem persists

As a website owner:

  • Check server error logs immediately
  • Review recent code changes
  • Verify database connections
  • Contact your hosting provider if needed

How do HTTP error codes affect SEO?

HTTP error codes can impact SEO in several ways:

  • 404 errors: Donโ€™t directly hurt rankings but can indicate poor site maintenance
  • 301 redirects: Pass most SEO value to the new URL
  • 302 redirects: Donโ€™t pass SEO value permanently
  • 5xx errors: Can negatively impact rankings if frequent or prolonged
  • Custom error pages: Should provide good user experience but not be indexed

Can I customize HTTP error codes for my website?

Yes, you can customize how HTTP error codes are displayed to users:

  • Create custom error pages with your branding
  • Implement different responses based on user type (API vs. web)
  • Use server configuration files (.htaccess, nginx.conf) to customize behavior
  • Implement application-level error handling for dynamic responses

However, you should always return the correct HTTP status code even with custom pages.

What tools can help me monitor HTTP errors?

Several tools can help monitor and debug HTTP errors:

Free Tools

  • Google Search Console (for SEO-related errors)
  • Browser developer tools
  • Online HTTP status checkers

Paid Tools

  • Ahrefs or SEMrush (for comprehensive site audits)
  • Sentry or Rollbar (for application error monitoring)
  • New Relic or Datadog (for performance monitoring)

Server-Level Tools

  • Error logs analysis
  • Uptime monitoring services
  • Load balancer and CDN analytics

How often should I check for HTTP errors on my website?

Regular Monitoring Schedule:

  • Daily: Check critical pages and applications
  • Weekly: Review error logs and monitoring dashboards
  • Monthly: Comprehensive site audit for broken links and errors
  • Quarterly: Full website health assessment

Automated Monitoring: Set up alerts for:

  • Critical 5xx errors (immediate notification)
  • Spike in 4xx errors (daily digest)
  • New broken links (weekly report)
  • Performance degradation (real-time alerts)

For more information about web development basics and error handling, check out these helpful resources:


Conclusion: Mastering HTTP Error Codes for Better Web Development

Understanding HTTP error codes is fundamental to creating robust web applications and maintaining healthy websites. From the user-friendly 200 OK to the dreaded 500 Internal Server Error, each code tells a story about what happened during a web request.

The key takeaways from this comprehensive guide:

For Developers: Implement proper error handling, use correct status codes, and create meaningful error messages. Tools like VS Code shortcut keys can help you code more efficiently when debugging these issues.

For Website Owners: Monitor your site regularly, fix broken links promptly, and create custom error pages that help rather than frustrate users. Understanding these codes helps you communicate effectively with technical support.

For Users: Know that most HTTP errors are temporary. When you encounter them, try basic troubleshooting steps before assuming the worst.

The web development landscape continues evolving, but HTTP status codes remain a constant foundation for web communication. Whether youโ€™re building your first website or managing enterprise applications, mastering these codes will make you a more effective developer and a savvier internet user.

Remember, every error is an opportunity to improve user experience. By implementing proper error handling, monitoring, and user-friendly messages, you transform potentially frustrating moments into opportunities to guide users toward success.

Ready to dive deeper into web development? Explore our guide on how to start learning to code and discover the programming fundamentals that will help you handle HTTP errors like a pro.

Tags

Share

Sandhya Ramakrishnan

Sandhya Ramakrishnan is a STEM enthusiast with several years of teaching experience. She is a passionate teacher, and educates parents about the importance of early STEM education to build a successful career. According to her, "As a parent, we need to find out what works best for your child, and making the right choices should start from an early age". Sandhya's diverse skill set and commitment to promoting STEM education make her a valuable resource for both students and parents.

Related posts