What is localhost? Loopback, 127.0.0.1 and ::1
localhost normally refers to the machine from which a request is made. Its familiar addresses are IPv4 127.0.0.1 and IPv6 ::1. Traffic to them is handled inside that machine’s network stack rather than travelling through the home router to the Internet. A localhost test therefore answers a narrow question: does the service work locally?
The loopback address ranges
IPv4 reserves the whole 127.0.0.0/8 block for loopback, although examples almost always use 127.0.0.1. IPv6 has the special address ::1/128. Their roles are described in RFC 1122 and RFC 4291. The name localhost usually resolves to these addresses through local system configuration. A particular application may try IPv4 or IPv6 first, so success on one and failure on the other does not necessarily mean that the whole network is broken.
A local web server example
A developer starts an application listening at 127.0.0.1:8000 and opens http://localhost:8000 on the same computer. This is a useful test without exposing the application to other devices. If a phone on the same Wi-Fi opens localhost:8000, the phone tries to connect to itself, not the developer’s computer. To reach the application from the phone, the service must listen on a suitable network interface, its firewall must permit the connection, and the phone must use the computer’s LAN address. Do not publish a development server to the wider Internet without appropriate protection.
Listening address versus outside access
A service bound only to 127.0.0.1 or ::1 is not directly reachable from another device. Binding to 0.0.0.0 in IPv4 generally means listening on all applicable IPv4 interfaces, but still does not guarantee outside access. Firewalls, containers, NAT and provider rules may block the path. Similar IPv6 behaviour depends on the application and system settings. An Internet-facing port check cannot confirm that a loopback-only service is functioning locally. Test locally first, then test each network boundary separately.
A common container or server mistake
Inside a container or on a remote server, localhost means that container or server, not your laptop. A database connection string pointing at localhost can therefore work during local development and fail after deployment when the database is on another machine. For diagnosis, identify where the client runs, then check the target hostname, port and address on which the service listens. Do not replace localhost with a public IP without evaluating exposure. Internal communication often calls for a private network address or a service-specific hostname.
