ExampleAddress

Localhost and 127.0.0.1 Explained

localhost refers back to the host using it. 127.0.0.1 is the familiar IPv4 loopback address and ::1 is IPv6 loopback.

Examples at a glance

Names and addresses

Hostname
localhost

A special name for the host using it.

IPv4 loopback
127.0.0.1

The familiar numeric loopback address.

IPv6 loopback
::1

The IPv6 equivalent.

Choose a local service

Local web server
http://localhost:8000/

8000 selects the service. It must be running on your device.

Your own host, not somebody else’s

If you open localhost on your phone, it points to your phone’s local environment, not the laptop running your app. In a container or virtual machine, that environment has its own network context.

Hostname versus address

localhost is a name with special-use handling; 127.0.0.1 and ::1 are numeric addresses. The whole IPv4 127.0.0.0/8 block is reserved for loopback, although 127.0.0.1 is the usual example.

Ports select the service

In http://localhost:8000/, 8000 is the port of a local HTTP service. A server must actually be listening there. To reach a server from another device, use an appropriate network address and deliberate server/network configuration; another device’s localhost will not work.

Loopback and listening on all interfaces

Binding a server to loopback limits its listening scope to that host. Binding to 0.0.0.0 generally means all available IPv4 interfaces, which can expose the service more broadly. These examples do not start a server or make any connection.

Related guides and tools

Primary sources