How to Access Localhost in Windows

Localhost allows you to access web servers running on your own computer using http://localhost or 127.0.0.1. It is commonly used by developers working with tools like XAMPP, Apache, Nginx, IIS, or other local server environments. If localhost is not working on your Windows system, this guide covers the most common causes and fixes - from a simple hosts file adjustment to port conflicts, proxy settings, and Windows Update regressions.

Quick answer: Start your local server, open a browser, and go to http://localhost. If it fails, the most common fix is opening C:\Windows\System32\drivers\etc\hosts as Administrator, commenting out ::1 localhost, and ensuring 127.0.0.1 localhost is present and uncommented. Save the file, restart your server, and try again.

editing the hosts file to access localhost in windows (Fix localhost)

What Is Localhost?

Localhost is a hostname that refers to your own computer. It uses the loopback network interface to let your system communicate with itself - no actual network connection is involved. When you type http://localhost into a browser, your computer looks up the address in its hosts file and connects to the local server software running on your machine.

There are two loopback addresses:

  • 127.0.0.1 - IPv4 loopback address
  • ::1 - IPv6 loopback address

Developers commonly use localhost to run and test web servers, databases, and applications locally before deploying them online. Common local server stacks include XAMPP, WAMP, Laragon, and standalone Apache or Nginx installs.

How to Access Localhost

  1. Start your local server (XAMPP, Apache, Nginx, IIS, etc.)
  2. Open your web browser
  3. Enter http://localhost in the address bar and press Enter

You can also access localhost using http://127.0.0.1, which points to the same local machine. If everything is working correctly, your local server dashboard or website should load immediately.

If your server uses a non-standard port, add it to the URL - for example: http://localhost:8080 or http://localhost:3000.

Fix Localhost Not Working on Windows - Hosts File Method

The most common cause of localhost failing on Windows is an IPv6 conflict. When ::1 localhost is active in the hosts file, Windows may route localhost requests through IPv6, which some local servers do not respond to correctly. The fix is to comment out the IPv6 entry and ensure the IPv4 entry is active.

  1. Navigate to C:\Windows\System32\drivers\etc
  2. Right-click the hosts file and open it with Notepad as Administrator
  3. Locate this line:
::1 localhost
  1. Add a hash (#) at the start to comment it out:
#::1 localhost
  1. Ensure this line exists and is not commented out (remove the # if it has one):
127.0.0.1 localhost
  1. Save the file (Ctrl+S) - you must have Administrator rights for this to succeed
  2. Restart your local server (stop and start Apache or your stack in XAMPP, etc.)
  3. Open http://localhost in your browser

If configured correctly, localhost should now resolve properly via IPv4.

Other Common Fixes If Localhost Still Does Not Work

1. Confirm Your Server Is Actually Running

The most common reason localhost does not load is simply that the web server is not running. Open XAMPP, Apache, or your server manager and verify that the service shows as active before troubleshooting anything else.

2. Flush the DNS Cache

Stale DNS cache entries can cause localhost to resolve to an old or incorrect address. Open Command Prompt as Administrator and run:

ipconfig /flushdns

Then try http://localhost again.

3. Check for Port Conflicts

If another application is using port 80 or 443, your local server cannot bind to it. Common culprits include Skype (which historically used port 80), IIS, other web servers, or antivirus software. To see what is using port 80, open Command Prompt as Administrator and run:

netstat -ano | findstr :80

Find the PID from the output, then check Task Manager to identify and stop the conflicting process. Alternatively, change your local server to use a different port (e.g. 8080) and access it at http://localhost:8080.

4. Check Windows Firewall and Security Software

Windows Defender Firewall or third-party antivirus software can silently block connections to localhost. To test if the firewall is the cause, temporarily disable it and try loading http://localhost. If it works with the firewall off, add an inbound rule to allow your server's port.

5. Disable or Bypass Proxy Settings

A proxy configured in Windows may intercept or block loopback traffic. Go to Settings → Network & Internet → Proxy and verify that Use a proxy server is turned off. If a proxy is required, ensure that localhost, 127.0.0.1, and ::1 are explicitly excluded from proxying.

6. Try 127.0.0.1 Directly

If http://localhost fails but http://127.0.0.1 works, the problem is in how localhost is being resolved - the hosts file fix above should correct it.

7. Windows 11 October 2025 Update (KB5066835)

If localhost stopped working after a Windows 11 update in October 2025, you may be affected by a known bug in cumulative update KB5066835. This update introduced a regression in HTTP.sys that caused IIS, XAMPP, and other local servers using HTTP/2 to fail with connection reset errors (ERR_CONNECTION_RESET). Microsoft confirmed the issue and released a fix. To resolve it:

  • Open Windows Update, click Check for Updates, install all available updates, and restart your PC. The fix was included in a subsequent update and installs automatically.
  • If updates are not yet available in your region, a temporary workaround is to disable HTTP/2 via registry: set EnableHttp2 and EnableHttp2OverTls to 0 under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS\Parameters, then restart.

Why Localhost May Not Work - Summary of Causes

  • IPv6/IPv4 conflict - ::1 taking priority over 127.0.0.1 in the hosts file
  • Server not running - web server software is stopped or crashed
  • Port conflict - another application occupying port 80, 443, or your server's configured port
  • Incorrect port - server is running on a non-default port not reflected in the URL
  • Firewall blocking connections - Windows Defender or third-party security software blocking loopback traffic
  • Proxy misconfiguration - system proxy intercepting or blocking localhost requests
  • Corrupted or missing hosts file entry - 127.0.0.1 localhost commented out or removed
  • Stale DNS cache - outdated cache entries pointing to incorrect addresses
  • Windows Update regression - known bugs introduced by specific cumulative updates

Security Considerations for Local Development

  • Do not expose your local server to the internet unless absolutely necessary - use firewall rules to restrict access to loopback only
  • Use HTTPS with a self-signed certificate when testing features that require a secure context (such as service workers or camera access)
  • Keep XAMPP, Apache, PHP, and other local server software updated to avoid known vulnerabilities
  • Avoid running local server software as a Windows service on shared or public networks

Frequently Asked Questions

What is the difference between localhost and 127.0.0.1?

They refer to the same destination - your own computer's loopback interface - but localhost is a hostname that gets resolved to an IP address by your hosts file. On most Windows systems, localhost resolves to 127.0.0.1 (IPv4) or ::1 (IPv6), depending on your hosts file and network settings. If localhost fails but 127.0.0.1 works, the issue is in how the hostname is being resolved.

Why does localhost work in one browser but not another?

Different browsers handle IPv6/IPv4 preference and proxy settings differently. If localhost works in one browser but not another, check the proxy and DNS settings in the failing browser. Some browsers also have their own DNS-over-HTTPS settings that bypass the local hosts file.

How do I find out what port my local server is using?

Check your server's configuration file. In XAMPP, open the Apache configuration panel - the default port is usually 80 for HTTP and 443 for HTTPS. If those ports are in use, XAMPP may have switched to 8080. Use netstat -ano | findstr :80 in an elevated Command Prompt to see what is listening on a given port.

Can I access localhost from another device on my network?

Not directly - localhost only resolves on the local machine. To access your local server from another device, use your machine's local IP address (e.g. http://192.168.1.x) and ensure your firewall allows inbound connections on the relevant port. Find your local IP with ipconfig in Command Prompt.

How do I edit the Windows hosts file?

Navigate to C:\Windows\System32\drivers\etc, right-click the hosts file, and open it with Notepad. You must choose Run as Administrator - the file will silently fail to save if you do not have elevated rights. Alternatively, search for Notepad in the Start menu, right-click it, select Run as Administrator, then open the hosts file from within Notepad.

Why does localhost show "refused to connect" vs "this site can't be reached"?

"Refused to connect" means the request reached the local machine but was rejected - usually because no server is listening on that port, or a firewall explicitly blocked it. "This site can't be reached" or a timeout typically means the hostname could not be resolved or the connection attempt received no response at all. The first suggests a server or firewall issue; the second suggests a hosts file or DNS problem.

Final Thoughts

Fixing localhost on Windows is usually straightforward once you identify which layer the problem is at. Start by confirming your server is running, then check the hosts file for an IPv6 conflict, verify port availability, and check your firewall and proxy settings. If the issue appeared after a Windows 11 update, checking for the latest Windows Update patches is often the fastest resolution.

By understanding how localhost resolution and loopback networking work, you can diagnose and restore your local development environment reliably - without needing to reinstall or reset anything.