What Is Localhost? (127.0.0.1, ::1, and Why It Matters)
Localhost is your computer talking to itself — the network address 127.0.0.1 (IPv4) or ::1 (IPv6) that loops back to the same machine. Plain explanation with use cases.
Short answer
Localhost is a hostname that always refers to the current device — your computer talking to itself over the network stack. It maps to the IP address 127.0.0.1 in IPv4 and ::1 in IPv6. Network requests to localhost never leave your machine; they go straight to the loopback interface and come back. This is why http://localhost:3000 reaches the dev server you just started.
The loopback range
The entire 127.0.0.0/8 block (about 16 million addresses from 127.0.0.0 to 127.255.255.255) is reserved for loopback. 127.0.0.1 is just the most commonly-used one. You can bind different services to 127.0.0.2, 127.0.0.3, etc. — handy when developing multi-host scenarios on one machine.
Where "localhost" comes from
The hostname-to-IP mapping is in your operating system's hosts file:
- Linux / macOS:
/etc/hosts - Windows:
C:\Windows\System32\drivers\etc\hosts
The default entry says:
127.0.0.1 localhost
::1 localhost
You can add custom mappings here to make myproject.test resolve to localhost too — useful for dev environments testing virtual hosts.
Why it matters for development
- Dev servers bind to it by default.
npm run devtypically opens onlocalhost:3000; nothing outside your machine can reach it. - Browser security treats localhost specially. Service workers, the Geolocation API, getUserMedia, and other secure-context APIs work on
localhostwithout HTTPS — they require HTTPS for any other origin. - Cookies are weird on localhost. Most browsers treat
localhostas a public suffix (similar to.com). Setting cookies on.localhostdoesn't work the way.example.comdoes. - CORS still applies. A page on
localhost:3000calling an API onlocalhost:8080is cross-origin (different ports = different origins). You'll need CORS headers.
localhost vs 127.0.0.1 — are they identical?
Almost. Subtle differences:
- localhost resolves via the OS hosts file, then DNS. Slight overhead per lookup (cached).
- 127.0.0.1 is a literal IP. No name resolution step.
- Some systems:
localhostresolves to::1(IPv6 loopback) first. If your service binds only to127.0.0.1(IPv4), you may get connection refused onlocalhostin some environments. Common dev confusion. - Cookies and Same-Origin Policy consider them the same origin in modern browsers, but legacy edge cases exist.
If your dev server "won't connect on localhost but works on 127.0.0.1," it's almost certainly an IPv4/IPv6 binding mismatch. Bind to 0.0.0.0 or [::] to listen on both.
Other reserved IP ranges
| Range | Purpose |
|---|---|
127.0.0.0/8 | Loopback (16M addresses) |
10.0.0.0/8 | Private network (large) |
172.16.0.0/12 | Private network (medium) |
192.168.0.0/16 | Private network (home routers) |
169.254.0.0/16 | Link-local (DHCP failed) |
0.0.0.0 | "All interfaces" when binding a server |
The "0.0.0.0 vs 127.0.0.1" decision when binding
- Bind to 127.0.0.1 — server only accepts connections from the same machine. Safest for dev.
- Bind to 0.0.0.0 — server accepts connections from any network interface, including your local network. Necessary for testing from your phone or another machine — but exposes the dev server to anyone on your network.
Related tools
Look up any public IP's owner and location: IP address lookup (won't work on private IPs like 127.0.0.1 — they have no public owner). For binary representations of IPv4 addresses: IP to binary.
Featured Tools
Try these free tools directly in your browser — no sign-up required.
IP Address Lookup
Look up any IP address to find its geolocation, ISP, country, city, and timezone. Instantly check your own IP or investigate any public IP address.
IP to Binary Converter
Convert IPv4 addresses to binary and back. Enter an IP address to see each octet in binary format, or enter binary to get the decimal IP.