What is localhost and 127.0.0.1?

localhost is the hostname that always refers to the machine you are using right now. When a program talks to localhost, it talks to itself. In practice, localhost resolves to the loopback address: 127.0.0.1 for IPv4 and ::1 for IPv6. These are the addresses your own device answers to, no matter what network it is connected to.

The loopback address

127.0.0.1 is the classic IPv4 loopback address, and ::1 is its IPv6 counterpart. Traffic sent to either of these never leaves your device. The operating system recognizes the destination as itself and loops the data straight back up the network stack, without touching your network card, your router, or the wider internet. That is where the name loopback comes from.

Interestingly, 127.0.0.1 is not the only loopback address. The entire 127.0.0.0/8 block, meaning every address from 127.0.0.0 to 127.255.255.255, is reserved for loopback. Any of those addresses points back at your own machine, though 127.0.0.1 is the one everyone uses by convention. These ranges are set aside by standards bodies, alongside the other reserved IP addresses and the private IP ranges that are never routed on the public internet.

Why developers use localhost

Loopback is a developer's best friend. When you build a website or an API, you usually run it on your own computer first to test it before anyone else can see it. The server listens on a loopback address and a port, and you open it in your browser using something like 127.0.0.1:3000 or localhost:8080. The number after the colon is the port, which tells your machine which local program should receive the connection.

Because loopback traffic never leaves the device, this is both fast and private. Your half-finished app is not exposed to the network, so you can experiment freely. Databases, development servers, and debugging tools all lean on loopback for exactly this reason.

The hosts file

How does the name localhost become an address in the first place? On most systems the mapping lives in a plain text hosts file, which your computer checks before it asks a DNS server. That file typically contains a line pointing localhost at 127.0.0.1, and another pointing it at ::1. Because the hosts file is consulted first, this lookup does not depend on any network being available. If you are curious about how names normally get resolved, see our guide on what a DNS server is.

Loopback vs your other IP addresses

It is easy to confuse loopback with the other addresses your device has, so it helps to separate them clearly. Your private LAN IP is the address your router assigns you inside your home or office network, often something like 192.168.x.x. Other devices on the same network can reach you at that address, and you can look it up on our find your local IP page. Your public IP is the single address the outside internet sees for your whole network, which you can check on our home page.

Loopback is different from both. Nobody else can ever reach your loopback address, not a device on your LAN and certainly not a server on the internet. It is strictly internal to the one machine.

What does 0.0.0.0 mean?

0.0.0.0 is another special address that often gets mentioned alongside loopback, and it means different things depending on context. As a bind address, when a server is told to listen on 0.0.0.0, it means listen on all network interfaces, including loopback and your LAN address, so the service becomes reachable from other machines. As a route or source address, 0.0.0.0 stands for the unspecified address, a placeholder that means no particular address or, in routing, the default route that matches everything. So 127.0.0.1 keeps a service private to your machine, while 0.0.0.0 tends to open it up.

Is 127.0.0.1 the same as my IP address?

No. 127.0.0.1 is the same on every device in the world, because it always means this machine. It is internal only and tells nobody anything about who or where you are. The IP address that identifies you on the internet is your public IP, which is unique to your network and assigned by your ISP. If a website logs an address for you, it logs your public IP, never your loopback address. You can see your real public IP any time by visiting our home page.

The takeaway

localhost and 127.0.0.1 are the way your device refers to itself. The whole 127.0.0.0/8 range and the IPv6 ::1 address are reserved for loopback, traffic to them never leaves the machine, and that is precisely what makes them so useful for testing and so irrelevant to your public identity online.

→ Check your IP address  ·  More guides