Localhost is the hostname a computer uses to refer to itself. It usually resolves to the IPv4 loopback address 127.0.0.1, or to ::1 for IPv6. When a program connects to localhost, the traffic is routed back to the same machine through the loopback interface and never leaves the computer or touches the network.
Key takeaways
- Localhost is a hostname, 127.0.0.1 is the standard IPv4 loopback address, and ::1 is the IPv6 loopback address.
- Traffic to localhost never leaves your machine, which makes it safe for local development and testing.
- Binding a service to 0.0.0.0 makes it reachable from other devices, while binding to 127.0.0.1 keeps it local only.
Type localhost into your browser and you are not visiting a website. You are asking your own computer to talk to itself. That simple idea — a loopback — powers local development, testing and network diagnostics on every modern operating system.
What is localhost?
Localhost is the hostname a computer uses to refer to itself. When a program connects to localhost, it connects back to the same machine, so the network traffic stays local instead of going out to the network.
It is not a real website and it is not a physical device. It is a reserved name that your operating system maps to a special loopback address, usually 127.0.0.1 for IPv4 and ::1 for IPv6. RFC 6761, the IETF standard for special-use domain names, reserves localhost for this purpose.
Every modern operating system has a loopback interface. Unlike a physical network card, it exists entirely in software. Any packet sent to it is immediately routed back to the same machine without touching any hardware or external network.
How does loopback work?
When you send a request to 127.0.0.1 or localhost, the TCP/IP stack recognizes the loopback address and routes the packet back to the same machine internally. The traffic does not reach the physical network interface and does not travel to any router.
The entire 127.0.0.0/8 block is reserved for loopback, which means any address from 127.0.0.1 to 127.255.255.254 routes back to the local machine. In practice, 127.0.0.1 is the standard address everyone uses.
That is different from ordinary network traffic, which is sent through a physical or virtual network interface, forwarded by routers and travels across the network to reach its destination. Loopback traffic skips all of that.
What is the difference between localhost and 127.0.0.1?
Localhost and 127.0.0.1 point to the same machine, but they are not identical. Localhost is a hostname. The address 127.0.0.1 is the standard IPv4 loopback address, and ::1 is the IPv6 loopback address.
| Term | What it is | What it resolves to | When to use it |
|---|---|---|---|
| localhost | Hostname | 127.0.0.1 or ::1 | General use, readable URLs |
| 127.0.0.1 | IPv4 loopback address | Itself | When you need IPv4 only |
| ::1 | IPv6 loopback address | Itself | When you need IPv6 only |
| 0.0.0.0 | Unspecified address | All interfaces | To listen on every interface |
| 192.168.x.x | LAN address | Your machine on the LAN | To reach it from other devices |
On most systems, localhost resolves through the hosts file before DNS is queried. On Linux that file is /etc/hosts, and on Windows it is C:\Windows\System32\drivers\etc\hosts. The usual entries are 127.0.0.1 localhost and ::1 localhost.
Using 127.0.0.1 skips hostname resolution and selects IPv4 directly. That matters when a service binds only to IPv4 and your system tries IPv6 first, which can cause a confusing connection error.
What is 0.0.0.0 and why does it matter?
0.0.0.0 is not a loopback address, and confusing it with localhost is a common security mistake. When a server binds to 0.0.0.0, it listens on all available IPv4 interfaces, including loopback and network-facing interfaces.
That means other devices on your network can connect to it. If you are on a public Wi-Fi network, anyone on that network may be able to reach the service, depending on your firewall. For local-only development, bind a service to localhost or 127.0.0.1 instead.
To make a service reachable from other devices on purpose, bind it to the machine's LAN IP address or to 0.0.0.0, then make sure the firewall allows the port. Check the binding before you share a local app with a colleague.
How do localhost and port numbers work together?
A hostname alone is not enough to reach a service. The address localhost identifies the machine, and the port number identifies which program on that machine receives the connection. That is why local development URLs look like http://localhost:8080.
When you open http://localhost with no port, the browser fills in the default port for the scheme, which is 80 for HTTP and 443 for HTTPS. A development server listening on port 8080 is not reachable that way, and the browser reports that the connection was refused.
Common development ports include 3000 for many JavaScript frameworks, 5000 for Python and Flask, 8000 for Django and Python servers, and 8080 as a general alternative web port. Ports below 1024 need extra privileges on a default Linux system, so development servers use higher numbers.
What is localhost used for?
Localhost is used for application development and testing, for network diagnostics, and for overriding or blocking domains. It is the safest place to run a service that is not ready for the internet.
Application development and testing
Web servers and development tools bind to localhost or 127.0.0.1 by default when running locally. This makes the application reachable only from the same machine, not from the network. A local web server on port 8080 is accessed at http://localhost:8080.
Overriding a domain for testing
You can map a domain name to a loopback address in your hosts file to redirect its traffic to a local server. Adding a line that maps example.com to 127.0.0.1 routes all requests for that domain to your local machine, which is useful for testing a site locally before deploying it.
Blocking a domain
Mapping a domain to 127.0.0.1 in the hosts file keeps requests for it on the local machine, but a local service listening on the requested port may still answer. For dependable blocking, use DNS filtering or a browser-level blocker instead. Our best web filter guide compares DNS filters that do this properly.
Network diagnostics
Pinging 127.0.0.1 confirms that the TCP/IP stack on the local machine is working, as Linuxize's localhost guide explains, independent of network hardware or connectivity. If ping 127.0.0.1 fails, there is a problem with the local networking stack itself, not with your router or internet connection.
You can also check which programs are listening on your machine. On Linux, ss -tlnp shows listening TCP connections. A value of 127.0.0.1:8080 means the service accepts connections only from the same machine, while 0.0.0.0:8080 means it listens on every interface.
Is localhost safe?
Localhost itself is safe, because traffic to 127.0.0.1 never leaves your machine and cannot be intercepted on the network. The risk comes from what you bind to it and what you expose.
A service bound only to localhost is reachable only by programs on your machine. A service bound to 0.0.0.0 is reachable from the network, so it needs authentication, a firewall rule and regular updates, just like any public service.
Another risk is a malicious website that tries to reach a local service. A page in your browser can attempt to connect to localhost on common ports, so local services that have no authentication can be a target. Keep local services up to date and do not run them with more privileges than they need.
For a general check of your network exposure, you can see your public address with our free what is my IP tool.
You can also check your domain's DNS with our free DNS lookup tool.
How do you fix common localhost errors?
Most localhost errors have a simple cause: the service is not running, it is listening on a different port, or it bound to a different address than the one in your URL.
“Localhost refused to connect” means nothing is listening on the address and port you requested. Confirm the service is running, then check what it actually bound to. A service listening on a different port produces this error even though it is running normally.
“Address already in use” means another process already holds that port on the same address. Note that 127.0.0.1:8080 and 0.0.0.0:8080 conflict, because 0.0.0.0 covers the loopback address too.
The service answers on 127.0.0.1 but not on localhost usually means localhost resolved to ::1 first and the service bound only to IPv4. Either configure the service to listen on ::1 as well, or use 127.0.0.1 explicitly in the URL.
If a new hosts entry has no effect, remember that browsers and long-running applications cache resolved names. Restart the client, and check for duplicate entries that map the same hostname to different addresses.
Localhost vs your LAN address: what is the difference?
Your LAN address, such as 192.168.1.10, identifies your machine on your local network. Other devices on the same network can reach a service bound to that address, if the firewall allows it.
Localhost identifies your machine to itself only. No other device can reach a service bound only to localhost, no matter what the firewall says, because the traffic never leaves the machine.
Use localhost when you want a service to be private to one machine. Use your LAN address when you want to test a site from your phone or share a local app with a colleague on the same network. Use a proper hosted server when you want anyone on the internet to reach it.
If you are setting up a home server, read our guide to securing your Wi-Fi first, so the network you expose it on is protected.
The bottom line
Localhost is your computer's way of referring to itself. It resolves to 127.0.0.1 for IPv4 or ::1 for IPv6, and traffic to it never leaves your machine, which makes it the safest place to develop and test.
Remember the one rule that matters: bind to 127.0.0.1 to keep a service local, and bind to 0.0.0.0 only when you mean to share it. You can check how your machine appears to the internet with our free what is my IP tool.
Frequently asked questions
What is localhost in simple terms?
Localhost is your computer talking to itself. When you type localhost in a browser, your computer sends the request back to a program running on the same machine, instead of sending it out to the internet.
What is the difference between localhost and 127.0.0.1?
Localhost is a hostname that the system resolver can map to 127.0.0.1 for IPv4, to ::1 for IPv6, or to both. Using 127.0.0.1 skips hostname resolution and selects IPv4 directly.
What is 0.0.0.0 and how is it different from localhost?
0.0.0.0 is not a loopback address. When a server binds to 0.0.0.0, it listens on all available network interfaces, so other devices can connect. When it binds to 127.0.0.1, only the local machine can connect.
Can other devices connect to my localhost?
No. Traffic sent to 127.0.0.1 or localhost never leaves the machine. To allow external connections, the service must bind to the machine's LAN IP address or to 0.0.0.0, and the firewall must allow the port.
Why does my app use localhost:3000 or localhost:8080?
Those are common development ports. Port 3000 is used by many JavaScript frameworks, and 8080 is a common alternative web port. Ports below 1024, such as 80 and 443, need extra privileges, so development servers use higher numbers.
Why do I get localhost refused to connect?
Nothing is listening on the address and port you requested. Check that the service is running, then check which port it actually bound to. A service listening on a different port produces this error even though it is running normally.
Is localhost safe?
Yes, for local use. Traffic to localhost never leaves your machine, so it cannot be intercepted on the network. The risk comes from binding a local service to 0.0.0.0 by mistake, which can expose it to your whole network.
What is the IPv6 equivalent of localhost?
The IPv6 loopback address is ::1. It behaves the same as 127.0.0.1 for IPv6 traffic, and localhost can resolve to either address depending on your system.
Sources
The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.
Checked against Linuxize's localhost guide, IETF RFC 6761 and the IANA special-use address registries.
How we write and fact-check →