ShareYourGroupShareYourGroupIP and Internet

127.0.0.1 and localhost explained

127.0.0.1 is the address every device uses for itself. Data sent to it never leaves the device.

The loopback address

The whole block from 127.0.0.0 to 127.255.255.255 is reserved for loopback: traffic that a device sends to itself. Nearly everyone uses just the first usable address, 127.0.0.1. The name localhost points to it on every system. In IPv6 the same job is done by the single address ::1.

When a program connects to 127.0.0.1, the data goes down into the system's network software and straight back up again. No network card, cable, Wi-Fi or router is involved. It works with the internet unplugged.

What it is used for

ping 127.0.0.1

If this fails, the fault is in the computer's own network set-up, not in the cable or Wi-Fi.

"127.0.0.1 refused to connect"

This browser message means: your computer is fine, but no program is listening on that port right now. Usual reasons:

  1. The local server or app is not running. Start it.
  2. It is running on a different port. Check the number it printed when it started.
  3. It is listening on the IPv6 address only, or the IPv4 one only. Try localhost, 127.0.0.1 and [::1] in turn.
  4. A firewall or security program is blocking it.
  5. You followed a link meant for someone else's computer. An address with 127.0.0.1 in it only ever works on the machine that runs the program; it can never be shared with another person.

Addresses that look similar

AddressMeaning
127.0.0.1This device itself (loopback)
localhostThe name for 127.0.0.1 and ::1
::1Loopback in IPv6
0.0.0.0"No particular address". A server listening on 0.0.0.0 accepts connections on every address the device has, so other devices on the network can reach it
192.168.x.xThe device's private address on the local network, which other devices in the house can reach

The difference between 127.0.0.1 and 0.0.0.0 matters for safety. A test server bound to 127.0.0.1 can be reached only from the same computer. Bound to 0.0.0.0, it can be reached by everyone on the same Wi-Fi, which you may not want in a cafe.

The hosts file

Every system has a small text file named hosts that is checked before DNS. It is where "localhost means 127.0.0.1" is written down. Pointing a site's name at 127.0.0.1 in this file is an old way to block that site on one computer: the browser then looks for it on the device itself and finds nothing. If a site you need suddenly fails on one computer only, an entry in this file left by some tool is worth checking.

Can someone hack me through 127.0.0.1?

Not from outside. The address exists only inside each device; a stranger's 127.0.0.1 is their own machine.

Why do scam messages say my IP address is 127.0.0.1?

It is a joke at the scammer's expense, or a sign they know nothing: that address is everyone's own computer.

Is localhost the same as my IP address?

No. Localhost always means "this device" and cannot be reached by others. Your private and public addresses are how other devices reach you.