Localhost is the standard hostname a computer uses to refer to itself, and it normally resolves to the loopback address 127.0.0.1 in IPv4 or ::1 in IPv6. Traffic sent to localhost never leaves your machine, which makes it ideal for running and testing software privately.
What localhost means
Every networked operating system includes a virtual network interface called the loopback interface. Anything a program sends to it is immediately handed back to the same computer's network stack, as if it had arrived from the network. No physical network card, cable or Wi‑Fi radio is involved.
The name localhost is simply a convenient label for that interface. When you type http://localhost:8000 in a browser, the operating system translates localhost into a loopback address and connects to whichever program is listening on port 8000 on your own computer. The interface is called lo on Linux, lo0 on macOS and BSD, and appears as "Loopback Pseudo-Interface 1" on Windows.
127.0.0.1, ::1 and the loopback range
IPv4: the whole 127.0.0.0/8 block
The IPv4 standards reserve the entire 127.0.0.0/8 block (every address from 127.0.0.0 to 127.255.255.255) for loopback. That is roughly 16.7 million addresses, but in practice almost everyone uses 127.0.0.1. On Linux, the other addresses in the block also work out of the box, so 127.0.0.2 reaches your machine too; some tools use them to run several local services on the same port. Packets addressed to 127.x.x.x must never appear on a real network, and routers drop them.
IPv6: a single address
IPv6 is far less generous: its loopback is exactly one address, ::1 (shorthand for 127 zero bits followed by a one). In URLs, IPv6 addresses go inside square brackets, so a local web server would be http://[::1]:8000. If you want to learn more about how the two protocol versions differ, see IPv4 vs IPv6.
How the name gets resolved
The mapping from localhost to these addresses usually comes from the local hosts file rather than from DNS. You can find it at /etc/hosts on macOS and Linux and at C:\Windows\System32\drivers\etc\hosts on Windows. A typical file contains lines like:
127.0.0.1 localhost
::1 localhost
RFC 6761 designates localhost. as a special-use domain name, so resolvers and applications are expected to treat it as the loopback address rather than ask DNS servers about it.
Localhost vs your private and public IP
A computer typically has several addresses at once, and confusing them is a common source of "it works on my machine" problems.
| Address | Example | Who can reach it |
|---|---|---|
| Loopback | 127.0.0.1, ::1 | Only programs on the same computer |
| Private (LAN) | 192.168.1.23 | Other devices on the same local network |
| Public | Assigned by your ISP | The internet, subject to your router and firewall |
| Unspecified | 0.0.0.0, :: | Not a destination; when a server binds to it, it listens on every interface |
The difference between binding a server to 127.0.0.1 and to 0.0.0.0 matters. A database or development server bound to 127.0.0.1 is invisible to every other device. The same server bound to 0.0.0.0 accepts connections on all of the machine's addresses, including its LAN address, so a phone on the same Wi‑Fi could connect to it. Our guide to public vs private IP addresses covers the other two rows in more detail.
How developers use localhost
Localhost is where most web and app development happens. Running a service locally means no one else can reach it, there is no network latency, and you do not need an internet connection. Some familiar examples:
python3 -m http.server 8000serves the current folder athttp://localhost:8000.- Django's
python manage.py runserverlistens on127.0.0.1:8000by default. - Many JavaScript frameworks start development servers on ports such as 3000 or 5173.
- Databases like PostgreSQL (5432), MySQL (3306) and Redis (6379) are commonly configured to listen only on localhost for safety.
The number after the colon is the port, which identifies the specific program. See common network ports for a reference of what usually runs where.
Browsers also give localhost special treatment. The W3C Secure Contexts specification treats http://localhost as "potentially trustworthy", so features that normally require HTTPS, such as service workers, generally work on localhost without a certificate.
Common localhost errors and fixes
Connection refused
Messages such as ERR_CONNECTION_REFUSED or ECONNREFUSED mean your computer received the request but nothing was listening on that port. Check that the server is actually running, that it did not crash on start-up, and that you are using the right port number.
Address already in use
If a server fails with EADDRINUSE or "address already in use", another process already holds the port. Find it with:
# macOS / Linux
lsof -i :8000
# Windows
netstat -ano | findstr :8000
Then stop that process or start your server on a different port.
Works on 127.0.0.1 but not on localhost (or vice versa)
Because localhost can resolve to both ::1 and 127.0.0.1, a client may try IPv6 first while the server listens only on IPv4. Some runtimes, including recent versions of Node.js, return the operating system's address order as-is, which often puts ::1 first. Fix it by making the server listen on both, or by connecting to 127.0.0.1 explicitly.
Localhost inside containers and virtual machines
Inside a Docker container or virtual machine, localhost refers to the container or VM itself, not to your computer. Docker Desktop provides the hostname host.docker.internal for reaching services on the host. In the other direction, publish the container's port (for example -p 8080:80) so your browser can reach it on localhost:8080.
Other devices cannot connect
If a phone on your Wi‑Fi cannot reach your development server, the server is probably bound to 127.0.0.1. Bind it to 0.0.0.0 or your LAN address, allow it through your firewall, and connect using your computer's private IP.
Is localhost safe?
Localhost traffic stays inside your computer, so it cannot be intercepted on the network. That does not make every local service harmless. Any program running on the same machine, including malware or a malicious web page script in your browser, can attempt to connect to local ports. Developers should still use authentication on local admin interfaces, avoid leaving debug servers running indefinitely, and never assume that "only localhost" means "only me" on a shared machine.
Frequently asked questions
Is 127.0.0.1 the same as localhost?
Usually, yes. localhost is a name and 127.0.0.1 is the IPv4 loopback address it normally resolves to. On systems with IPv6 it may also resolve to ::1, and both lead back to the same computer.
Can I visit someone else's localhost?
No. Typing localhost always refers to the device you are typing on. To reach a service on another computer you need its private IP on the same network, or its public IP with appropriate port forwarding.
Does localhost need an internet connection?
No. The loopback interface works even when Wi‑Fi and Ethernet are disconnected, which is why local development works offline.
Why does my public IP not show 127.0.0.1?
Loopback addresses are never sent over the network, so websites see your public IP instead. You can check yours on the ToolsForAnyone home page.