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 actually leaves your machine, which is exactly what makes it so useful for running and testing software privately.
What localhost means
Every networked operating system carries a virtual network interface called the loopback interface. Anything a program sends to it gets handed straight back to the same computer's network stack, as if it had just arrived from the network outside. No physical network card, cable or Wi‑Fi radio is involved at any point.
The name localhost is really just a convenient label for that interface. Type http://localhost:8000 into a browser, and the operating system quietly translates localhost into a loopback address and connects to whatever's listening on port 8000 on your own computer. The interface itself goes by lo on Linux, lo0 on macOS and BSD, and shows up 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's roughly 16.7 million addresses, though in practice almost everyone just uses 127.0.0.1. On Linux, the rest of the block works too, right out of the box, so 127.0.0.2 reaches your machine just as well; some tools use addresses like that to run several local services on the same port. Packets addressed to 127.x.x.x must never show up on a real network, and routers simply drop them if they try.
IPv6: a single address
IPv6 is far less generous here: its loopback is exactly one address, ::1 (shorthand for 127 zero bits followed by a single one). In URLs, IPv6 addresses go inside square brackets, so a local web server would read http://[::1]:8000. Curious how the two protocol versions differ more broadly? 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 at all. You'll 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 directly, rather than bother asking any DNS server about it.
Localhost vs your private and public IP
A computer typically juggles several addresses at once, and mixing them up is a classic source of "it works on my machine" headaches.
| 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 more than people expect. A database or development server bound to 127.0.0.1 is invisible to every other device, full stop. Bind that same server to 0.0.0.0, though, and it accepts connections on all of the machine's addresses — including its LAN address — so a phone sitting on the same Wi‑Fi could connect right 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 actually happens day to day. Run a service locally and no one else can reach it, there's no network latency to worry about, and you don't even need an internet connection. A few 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, identifying which specific program you're talking to. See common network ports for a reference of what usually runs where.
Browsers give localhost special treatment too. The W3C Secure Contexts specification treats http://localhost as "potentially trustworthy," so features that would normally demand HTTPS — service workers, for instance — generally just work on localhost without a certificate in sight.
Common localhost errors and fixes
Connection refused
Messages like ERR_CONNECTION_REFUSED or ECONNREFUSED simply mean your computer received the request, but nothing was listening on that port. Check that the server is actually running, that it didn't quietly crash on start-up, and that you're using the right port number.
Address already in use
If a server fails with EADDRINUSE or "address already in use," some other process already holds that port. Track it down with:
# macOS / Linux
lsof -i :8000
# Windows
netstat -ano | findstr :8000
Then stop that process, or just start your own 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 only listens on IPv4 — and the connection just fails. Some runtimes, including recent versions of Node.js, pass through the operating system's address order as-is, which often puts ::1 first. Fix it by making the server listen on both, or simply connect 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 specifically for reaching services on the host. Going the other direction, publish the container's port (-p 8080:80, say) so your browser can reach it on localhost:8080.
Other devices cannot connect
Phone on your Wi‑Fi can't 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 instead, allow it through your firewall, and connect using your computer's private IP.
Is localhost safe?
Localhost traffic stays inside your computer, so it can't be intercepted on the network — but that doesn't make every local service harmless. Any program running on the same machine, malware included, or a malicious script on some web page in your browser, can still try to connect to local ports. Developers should still lock down local admin interfaces with authentication, avoid leaving debug servers running indefinitely, and never assume "only localhost" means "only me" on a machine other people also use.
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 either way you end up back at the same computer.
Can I visit someone else's localhost?
No. Typing localhost always points at the device you're typing on — nothing else. To reach a service on another computer, you need its private IP on the same network, or its public IP with appropriate port forwarding set up.
Does localhost need an internet connection?
No. The loopback interface works even with Wi-Fi and Ethernet both disconnected, which is exactly why local development carries on fine offline.
Why does my public IP not show 127.0.0.1?
Loopback addresses are never sent over the network, so websites only ever see your public IP instead. You can check yours on the What's My IP Number page.
Kommentare
Teilen Sie einen Tipp, stellen Sie eine Frage oder erzählen Sie, wie das Tool bei Ihnen funktioniert hat.