The Simple Definition
A loopback address never leaves the device. If you connect to 127.0.0.1, your operating system routes that traffic internally. It does not go to your router, switch, Wi-Fi network, modem, ISP, or the public internet. The kernel intercepts the packet immediately and delivers it to a listening process on the same machine.
Loopback Addresses to Know
| Address or Name | Protocol | Meaning |
|---|---|---|
127.0.0.1 | IPv4 | The most common loopback address |
127.0.0.0/8 | IPv4 | The entire IPv4 loopback block (16 million addresses) |
::1 | IPv6 | The single IPv6 loopback address |
localhost | Hostname | A name that usually resolves to a loopback address |
The Full 127.0.0.0/8 Block
IPv4 reserves the entire 127.0.0.0/8 block for loopback. That is 16,777,216 addresses, of which only 127.0.0.1 sees practical use. RFC 1122 reserves the block; it does not require that only 127.0.0.1 be used. Addresses such as 127.0.0.2 or 127.1.2.3 are also valid loopback addresses that the kernel will accept. They can be useful in development and testing scenarios where you want to bind multiple services to distinct loopback IPs without setting up a full virtual network interface. That said, 127.0.0.1 is the universally conventional choice, and any other address in the block will confuse tools and people who do not expect it.
IPv6 Loopback: ::1
IPv6 compresses the entire loopback concept into a single address: ::1, which expands to 0000:0000:0000:0000:0000:0000:0000:0001. Unlike IPv4, there is no large reserved block. When a process connects to ::1, the behavior is identical to 127.0.0.1 — the packet stays on the machine. Operating systems that support both protocols will typically listen on both if you bind to localhost, depending on the platform and socket options. That is one reason localhost and 127.0.0.1 can behave differently on a dual-stack system.
How the Kernel Handles Loopback Traffic
Loopback traffic does not require a physical NIC. The operating system maintains a virtual loopback interface — named lo on Linux, lo0 on macOS and BSD systems — that has no hardware behind it. When a packet is sent to a loopback address, the kernel routes it directly to that interface and delivers it to the receiving socket without going through any driver, cable, or wireless radio. This means loopback is extremely fast and fully reliable; it cannot have packet loss, cable faults, or driver issues. It is useful for inter-process communication (IPC) between services that run on the same host.
localhost Resolution: Hosts File vs DNS
The name localhost is not resolved by DNS under normal circumstances. Most operating systems resolve it locally first, either from a built-in rule or from the hosts file. On Linux and macOS, /etc/hosts typically contains a line mapping localhost to 127.0.0.1 and ::1. On Windows, C:\Windows\System32\drivers\etc\hosts does the same. Because this resolution happens before a DNS query, it is fast and does not depend on a working DNS resolver. If localhost behaves unexpectedly, checking the hosts file is often the right first step.
Common Use Cases
- Development web servers, API servers, and front-end build tools typically default to
localhost:3000,127.0.0.1:8080, or similar addresses so the app is accessible from the same machine but not the network. - Databases such as PostgreSQL and MySQL default to accepting connections only on loopback, which keeps them private unless explicitly reconfigured.
- Inter-process communication between microservices running on the same host: a backend service might reach a cache, queue, or sidecar proxy over
127.0.0.1. - Testing: binding a mock server to a loopback address lets automated tests run without a real network or DNS dependency.
- Security tools, proxies, and VPN clients often insert themselves by listening on loopback and redirecting local traffic through themselves.
Binding to 0.0.0.0 vs 127.0.0.1
When a server starts, it must choose which address to listen on. Binding to 127.0.0.1 means only connections originating on the same machine are accepted. Binding to 0.0.0.0 (IPv4) or :: (IPv6) means the server accepts connections on all available network interfaces, including Ethernet, Wi-Fi, VPN adapters, and any others. This is a significant difference. A database bound to 0.0.0.0 is reachable from the LAN or beyond if the firewall permits it. Many tools default to one or the other, and the default is not always obvious from the documentation.
Security Implications of Accidental Exposure
Accidentally binding a service to 0.0.0.0 instead of 127.0.0.1 is a common source of unintended exposure. Admin dashboards, developer tools, database management interfaces, and debug endpoints are frequently started with defaults that bind broadly. If a firewall does not block the port, that service is reachable by other devices on the same network and possibly beyond. Before running any service in production or on a shared network, verify which address it listens on using ss -tlnp or netstat -tlnp on Linux, or netstat -an on Windows. Any service that does not need to be reachable from the network should be bound explicitly to 127.0.0.1.
Loopback vs Your LAN IP
Your LAN IP might look like 192.168.1.42 or 10.0.0.15. Other devices on your home network can usually reach that address if firewall rules allow it. 127.0.0.1 is different: every device has its own loopback. Your laptop's 127.0.0.1 is your laptop. Your phone's 127.0.0.1 is your phone. There is no path between them over loopback.
How Loopback Helps Troubleshooting
ping 127.0.0.1confirms the local IPv4 stack is responsive and the loopback interface is up.ping ::1does the same for IPv6.curl http://localhost:8080checks whether a local service is listening and returning a response, without involving DNS or the network.- If loopback works but LAN access fails, the problem is likely the binding address, a firewall rule, routing, or another network device.
- If
localhostbehaves differently from127.0.0.1, IPv6 resolution via the hosts file or a dual-stack socket issue may be involved.
Frequently Asked Questions
What is 127.0.0.1?
127.0.0.1 is the most common IPv4 loopback address. It means this same device, not another computer on the network.
What is localhost?
localhost is a hostname that normally resolves to a loopback address such as 127.0.0.1 for IPv4 or ::1 for IPv6.
Can other devices connect to 127.0.0.1 on my computer?
No. 127.0.0.1 is local to each device. Other devices need your LAN IP address, public IP address, or a configured hostname.