# https://tunnels.io/learn/localhost-vs-127-0-0-1

[Home](https://tunnels.io/) / [Learn](https://tunnels.io/learn) / localhost vs 127.0.0.1

Learn

# localhost vs 127.0.0.1: what is the difference?

localhost is a hostname. 127.0.0.1 is an IPv4 address. Your machine resolves the name localhost to a loopback address, usually 127.0.0.1 or the IPv6 address ::1, and traffic sent there never leaves the machine. They behave the same most of the time, but the name goes through a lookup that can answer differently, which is where connection errors come from.

## What is the difference between localhost and 127.0.0.1?

`127.0.0.1`` is a literal IPv4 address, so the operating system can use it straight away with no lookup. `localhost`` is a name that has to be resolved first, and the resolver decides which address it becomes. On almost every system that answer is 127.0.0.1 or ::1, which is why the two feel interchangeable, but only one of them depends on a resolution step that can be edited, cached, or answered over IPv6.

The four values you will actually type

| Value | What it is | What it reaches |
| --- | --- | --- |
| `localhost` | A hostname, resolved on your own machine | Whichever loopback address it resolves to |
| `127.0.0.1` | The IPv4 loopback address | This machine only |
| `::1` | The IPv6 loopback address | This machine only |
| `0.0.0.0` | A wildcard used when binding a listener, not a destination | Every IPv4 address the machine holds, including the LAN one |
| `::` | The IPv6 wildcard for binding | Every IPv6 address, plus IPv4 when the socket is dual-stack |

## What is the loopback interface?

It is a virtual network interface that every operating system creates for itself, called `lo`` on Linux and `lo0`` on macOS. Packets sent to it are handed straight back up the local network stack, so they never reach your Ethernet or Wi-Fi adapter, never cross a cable, and never touch a router. IPv4 reserves the entire 127.0.0.0/8 block for this purpose, which is why 127.0.0.2 also works on Linux, while IPv6 reserves a single address, ::1.

## Is localhost always 127.0.0.1?

No. localhost is resolved like any other name, normally from your hosts file at `/etc/hosts`` or `C:\Windows\System32\drivers\etc\hosts``, and that file can list ::1 first, point somewhere unexpected, or be missing the entry entirely. RFC 6761 requires resolvers to keep localhost pointing at a loopback address and to never send the query out to DNS, so the name stays local; it does not promise the answer is IPv4. Inside a Docker container the same word means the container itself rather than your host, which is a separate and very common surprise.

## What about ::1 and IPv6?

::1 is the IPv6 loopback address, the exact counterpart of 127.0.0.1. On a dual-stack machine localhost usually resolves to both, the client picks one, and many clients now try ::1 first. If your server is listening only on the IPv4 loopback and the client connects over IPv6, you get connection refused even though both processes are on the same machine. Node.js 17 changed its default DNS result order and turned this into a well-known source of ECONNREFUSED on localhost.

## Why can other devices not reach my localhost?

Because localhost is not a shared address, it is a per-machine one. Your phone's localhost is your phone, and your colleague's localhost is their laptop, so a URL like http://localhost:3000 means something different on every device that opens it. If a server is bound to 127.0.0.1 the kernel accepts connections only when they arrive on the loopback interface, so a request from another machine is refused before your application code ever sees it. Even once the binding is fixed, home and office networks sit behind NAT and a firewall, so nothing outside the local network can open a connection to you.

## What does binding to 0.0.0.0 do?

0.0.0.0 is not somewhere you connect to. It is a wildcard you pass when opening a listening socket, and it means accept connections on every IPv4 address this machine holds. That includes the loopback address and the LAN address, so another device on the same Wi-Fi can now reach you at something like http://192.168.1.24:3000, and :: does the same job for IPv6. Binding that wide also exposes the server to everyone else on that network, which matters on shared or public Wi-Fi, and it still does not make you reachable from the internet.

## How do you make a local server reachable?

Start by binding to 0.0.0.0 instead of 127.0.0.1, which covers other devices on the same network and is usually all a phone on the same Wi-Fi needs. Going beyond that network requires one of two things: an inbound path into your machine, meaning a router port forward plus a stable DNS name plus your own TLS certificate, or an outbound tunnel, where a client on your machine connects out to a public server that relays traffic back down the same connection.

The tunnel is the common answer because it works from behind NAT, needs no inbound port open, and terminates HTTPS for you. [How to expose localhost](https://tunnels.io/learn/how-to-expose-localhost) compares all four approaches with their trade-offs, and [what is tunneling](https://tunnels.io/learn/what-is-tunneling) covers the mechanism itself.

## Related reading

[How to expose localhost to the internet Tunnel, SSH forwarding, router port forwarding or deploying it, with the honest trade-offs of each.](https://tunnels.io/learn/how-to-expose-localhost) [How to test a mobile app against localhost Your phone cannot see your laptop's loopback. Three ways to point a real device at your local API.](https://tunnels.io/learn/how-to-test-a-mobile-app-against-localhost) [What is tunneling? Wrapping one protocol inside another so traffic crosses a network that would not otherwise carry it.](https://tunnels.io/learn/what-is-tunneling)

Everything else is indexed on [Learn](https://tunnels.io/learn).

## How does tunnels.io fit into this?

tunnels.io runs the outbound half for you. A client on your machine opens a connection to our servers, and we give you a public HTTPS URL that forwards to whichever local port you name, so a webhook provider, a phone on cellular data, or a client in another country reaches the server that is still listening on your laptop. Your app can even stay bound to 127.0.0.1, because the tunnel client is on the same machine and reaches it over loopback.

The free Basic plan costs nothing, includes 4 GB of transfer a month and one tunnel, and issues a random URL, which is enough to answer the question this page is about. Paid plans add reserved subdomains, custom domains and TCP tunnels for services that are not HTTP.

[Get started →](https://tunnels.io/get-started)

## Common questions

### Is localhost slower than 127.0.0.1?

Not in any way you will measure from an application. Both end up on the same loopback interface and the same kernel path. Typing the literal address skips a name lookup, but that lookup is answered from the hosts file or a local cache in microseconds, so the difference is noise next to the request itself.

### Why does my server work on 127.0.0.1 but not on localhost?

Almost always because localhost is resolving to the IPv6 address ::1 while your server is listening only on the IPv4 loopback. Check what the process is actually bound to, then either listen on both stacks or bind to 0.0.0.0. Pinging localhost shows you which address the name produced, which confirms the diagnosis in a second.

### Can I use another loopback address like 127.0.0.2?

On Linux the whole 127.0.0.0/8 range is loopback, so 127.0.0.2 works out of the box and is a common trick for running several services that all want the same port number. On macOS you add the extra address to the lo0 interface first with ifconfig. Either way the traffic still never leaves the machine.

### Does binding to 0.0.0.0 put my app on the internet?

No. It makes your app reachable at every address your machine holds, which in practice means other devices on the same local network. Home and office routers use NAT and do not forward inbound connections by default, so the wider internet still cannot reach you without a port forward or a tunnel.

### Is localhost the same as my machine's LAN IP address?

No. A LAN address such as 192.168.1.24 belongs to a real network interface and other devices on that network can route to it. localhost and 127.0.0.1 are scoped to the machine itself and mean a different computer on every device that uses them.
