127.0.0.1 and Localhost Explained
Quick answer
127.0.0.1 is the IPv4 loopback address: it points back to your own machine. localhost is the conventional name for that loopback address, usually mapped by the operating system through the hosts file or resolver rules. Public DNS should not resolve localhost to a real server. If a browser says it cannot reach localhost, the problem is usually the local service, port, firewall, container binding, or hosts file.
On this page
What you'll learn
- Explain what 127.0.0.1 means
- Explain how localhost differs from a public DNS name
- Show where hosts files and resolvers fit in
- Debug common localhost and container binding problems
127.0.0.1 means "this machine."
When you connect to it, packets do not go to your router, your ISP, or the internet. The operating system routes them straight back to the same computer.
That is why developers use addresses like:
http://127.0.0.1:3000
http://localhost:3000They mean "connect to the service running on my own machine, on port 3000."
What 127.0.0.1 Is
127.0.0.1 is part of the IPv4 loopback range:
127.0.0.0/8The common address is:
127.0.0.1If an application opens a connection to 127.0.0.1, the network stack loops the connection back locally.
browser -> 127.0.0.1:3000 -> local app on the same machineNo external DNS provider is involved.
What Localhost Is
localhost is the human-readable name for loopback.
Most systems map it locally:
127.0.0.1 localhost
::1 localhostYou can usually find that mapping in:
| System | Hosts file |
|---|---|
| macOS / Linux | /etc/hosts |
| Windows | C:\Windows\System32\drivers\etc\hosts |
The hosts file is checked before normal DNS on most systems. That is why localhost works even when you are offline.
IPv4 vs IPv6 Localhost
There are two common loopback addresses:
| Address | Protocol | Meaning |
|---|---|---|
127.0.0.1 | IPv4 | loop back to this machine |
::1 | IPv6 | loop back to this machine |
Some tools prefer IPv6 first. If an app listens only on IPv4, this can matter:
curl http://localhost:3000
curl http://127.0.0.1:3000
curl http://[::1]:3000If 127.0.0.1 works but localhost fails, check whether the app is listening on IPv4, IPv6, or both.
Localhost Is Not Public DNS
This is the key point:
your localhost != someone else's localhostIf you send a colleague a URL like:
http://localhost:3000their browser tries to connect to port 3000 on their own machine.
To share a local app, use a proper hostname, a tunnel, a VPN, or deploy it somewhere reachable.
Why Local Dev Servers Use It
Localhost is useful because it is safe by default:
- it does not expose the service to the network
- it avoids public DNS changes
- it works offline
- it lets many apps use different ports on one machine
Examples:
npm run dev
# Vite starts on http://localhost:5173
go run ./cmd/api
# API starts on http://127.0.0.1:8080The port number chooses the local service. The hostname chooses the local interface.
127.0.0.1 vs 0.0.0.0
These are often confused:
| Address | Meaning for a server |
|---|---|
127.0.0.1 | Listen only for connections from this same machine |
0.0.0.0 | Listen on all IPv4 interfaces |
:: | Listen on all IPv6 interfaces |
If a dev server is bound to 127.0.0.1, another device on your Wi-Fi cannot reach it.
If it is bound to 0.0.0.0, another device may be able to reach it through your LAN IP:
http://192.168.1.25:3000Only do this intentionally. Firewalls and development servers are not a substitute for production access control.
Localhost in Containers
Containers add one more layer.
Inside a Docker container:
localhost = that containerNot your laptop. Not another container.
Common fixes:
- publish the container port with
-p 8080:8080 - bind the app inside the container to
0.0.0.0 - use the Docker service name to reach another container on the same network
If an app works inside the container but not from your browser, check port publishing first.
Debugging Checklist
If localhost is not working:
- Check the service is running.
- Check the port is correct.
- Try
127.0.0.1instead oflocalhost. - Try
::1if IPv6 may be involved. - Check the app bind address.
- Check firewall or security software.
- Check
/etc/hostsor the Windows hosts file. - If using Docker, check port publishing.
Useful commands:
curl -v http://127.0.0.1:3000
lsof -iTCP:3000 -sTCP:LISTEN
dig localhostFrequently asked questions
- What is 127.0.0.1?
- 127.0.0.1 is the standard IPv4 loopback address. Traffic sent there never leaves your machine; it is routed back to the local host.
- Is localhost the same as 127.0.0.1?
- Usually for IPv4, yes. localhost often resolves to 127.0.0.1 and may also resolve to ::1 for IPv6.
- Can other people access my localhost?
- No. Their localhost points to their own machine, not yours. To expose a local service, you need to bind it to a reachable interface and route traffic to it safely.
- Why does localhost work without public DNS?
- Operating systems treat localhost as a special local name. It is commonly defined in the hosts file and does not need an authoritative DNS lookup.
- What is ::1?
- ::1 is the IPv6 loopback address. It is the IPv6 equivalent of 127.0.0.1.
- Why does my app work on 127.0.0.1 but not from another device?
- The app is probably bound only to the loopback interface. Bind it to 0.0.0.0 or the machine's LAN address if you intentionally want other devices to connect.
Continue with DNS fundamentals
Follow a DNS lookup from the name you enter to the server that answers.
Learn how DNS works