Glossary

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 dev typically opens on localhost: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 localhost without HTTPS — they require HTTPS for any other origin.
  • Cookies are weird on localhost. Most browsers treat localhost as a public suffix (similar to .com). Setting cookies on .localhost doesn't work the way .example.com does.
  • CORS still applies. A page on localhost:3000 calling an API on localhost:8080 is 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: localhost resolves to ::1 (IPv6 loopback) first. If your service binds only to 127.0.0.1 (IPv4), you may get connection refused on localhost in 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

RangePurpose
127.0.0.0/8Loopback (16M addresses)
10.0.0.0/8Private network (large)
172.16.0.0/12Private network (medium)
192.168.0.0/16Private network (home routers)
169.254.0.0/16Link-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.

what is localhost 127.0.0.1 loopback address localhost vs 127.0.0.1 local development

Explore 300+ Free Tools

Utilko has tools for developers, writers, designers, students, and everyday users — all free, all browser-based.