127.0.0.1 is the loopback address, and localhost is the name that points to it: both mean "this device." Traffic sent to 127.0.0.1 localhost never leaves your computer. It doesn't touch your router or the internet. That's why a web app you run on your own machine opens at http://localhost or http://127.0.0.1, and why no website will ever see 127.0.0.1 as your address. Websites see the public IP your internet provider gave you, and the CheckIP homepage shows your real public IP. Seeing 127.0.0.1 in a log file or a browser error is normal and doesn't mean anyone is connected to you.

127.0.0.1 meaning: what the loopback address does

127.0.0.1 is the standard IPv4 loopback address. Data sent to it goes down into the operating system's network stack and comes straight back up to the same machine, without passing through a network card, a cable or the Wi-Fi radio.

The whole 127.0.0.0/8 block, from 127.0.0.0 to 127.255.255.255, is reserved for loopback. 127.0.0.1 is simply the one everyone uses. RFC 1122, section 3.2.1.3, says these addresses "MUST NOT appear outside a host." The range sits inside old class A space but was never given to any network, as the guide to IP address classes explains.

IPv6 has exactly one loopback address: ::1, the short form of 0:0:0:0:0:0:0:1, defined in RFC 4291. It does the same job as 127.0.0.1.

Loopback is one of three kinds of address on a computer; the other two are explained in public vs private IP.

Address Type Who can reach it
127.0.0.1 Loopback Only the device itself
192.168.1.10 Private (LAN) Devices on the same home or office network
Your public IP Public Any server on the internet you connect to

Localhost vs 127.0.0.1: what's the difference?

Localhost is a hostname, and 127.0.0.1 is an IP address. Your computer turns the name localhost into a loopback address before it connects, the same way it turns example.com into an IP. The two are usually interchangeable, but localhost can resolve to the IPv6 address ::1 instead of 127.0.0.1.

RFC 6761, section 6.3, treats localhost as a special name. Name resolution libraries should always answer it with a loopback address and should not send the query to a DNS server. Before any DNS lookup, the system also checks its hosts file. On Windows that file is C:\Windows\System32\drivers\etc\hosts, and on macOS and Linux it is /etc/hosts.

The IPv6 detail causes real bugs. Since version 17, Node.js returns addresses in the order the operating system gives them (the "verbatim" default in the Node.js DNS documentation), so localhost may come back as ::1 first. A server that listens only on 127.0.0.1 then refuses the connection. Typing 127.0.0.1 skips the name lookup entirely.

  localhost 127.0.0.1 ::1
What it is Hostname IPv4 address IPv6 address
IP version Either, depends on the system IPv4 only IPv6 only
Needs a name lookup Yes (hosts file or resolver) No No

What localhost:8080 and other port numbers mean

The number after the colon in localhost:8080 is a port. One IP address has 65,535 TCP ports, and each program that accepts connections listens on its own port. That's how several local sites run side by side on one laptop: one at localhost:3000, another at localhost:5500, a third at localhost:8080.

Port 8080 is registered with IANA under the service name "http-alt" (HTTP Alternate). It's the usual choice when port 80 is taken or when a second web server runs on the same machine. freeCodeCamp notes that the VS Code Live Server extension serves pages from 127.0.0.1 on port 5500.

A URL without a port uses the protocol's default. http://localhost goes to port 80, and https://127.0.0.1 goes to port 443. That second address only loads if a local server is listening on 443 with a certificate. Otherwise you get a refusal or a certificate warning.

What is 127.0.0.1 localhost used for?

Localhost is used to run and test software on one machine before anyone else can reach it. Developers open local copies of websites and databases there. Browsers treat it as a trusted origin, and a hosts file line that points a domain at 127.0.0.1 blocks that domain.

  • Testing sites and apps. A WordPress copy in XAMPP or a Node or Python project runs at localhost, and nothing is public until you deploy it.
  • Testing HTTPS-only features. MDN's page on secure contexts lists localhost, 127.0.0.0/8 and ::1 as potentially trustworthy, so http://localhost counts as a secure context. Service workers and other features that normally need HTTPS work there without a certificate.
  • Blocking sites with the hosts file. A line such as "127.0.0.1 ads.example.com" sends that domain back to your own computer, so it fails to load. Malware uses the same file to redirect real sites, so an unknown entry there is worth investigating.
  • Checking the network stack. Running ping 127.0.0.1 in a terminal should return replies in under 1 ms. That proves TCP/IP works inside the computer. It says nothing about your internet connection.

127.0.01, 127.1 and other ways people type it

Typing 127.0.01 in a browser address bar still opens 127.0.0.1. The WHATWG URL Standard, which modern browsers follow, accepts IPv4 addresses written with fewer than four parts and fills in the missing zeros. Under that rule 127.0.01 and 127.1 both become 127.0.0.1.

The URL parser in Node.js implements the same standard: http://127.0.01/ and http://127.1/ both come out as host 127.0.0.1. "127.0. 0.1" with a space is invalid. Type all four parts in config files, where parsers are stricter.

127.0.0.2 is loopback too. Most servers bind only to 127.0.0.1, so they won't answer on 127.0.0.2.

0.0.0.0 vs 127.0.0.1 when you run a server

A server bound to 127.0.0.1 accepts connections only from the same computer. A server bound to 0.0.0.0 listens on every network interface, so a phone, a second laptop or anyone else on the same Wi-Fi can reach it at your computer's LAN address. 0.0.0.0 is not a place to browse to. It means "all interfaces" when a program starts.

Some tools pick 0.0.0.0 for you. According to the Python documentation, python -m http.server binds to all interfaces on port 8000 unless you pass --bind 127.0.0.1. On café or dorm Wi-Fi, strangers can then open the folder you shared. Keep test servers on 127.0.0.1 unless another device needs them. In a hosts file, "0.0.0.0 example.com" simply blocks the domain.

How to fix "localhost refused to connect"

Chrome shows "This site can't be reached" with "localhost refused to connect" and the code ERR_CONNECTION_REFUSED when nothing on your computer is listening on the port you typed. The fix is almost always to start the server, or to open the exact address and port it prints in the terminal when it starts. If the port is already taken, our guide shows how to check open ports on your computer.

What you see Likely cause Fix
ERR_CONNECTION_REFUSED The server isn't running, or you typed the wrong port Start the server and copy the URL it prints
Works on 127.0.0.1 but not on localhost localhost resolves to ::1, and the server listens only on IPv4 Use 127.0.0.1, or make the server listen on ::1 as well
"Address already in use" when the server starts Another program holds that port Pick another port, or close the other program (on Windows, netstat -ano | findstr :8080 shows its process ID)
Your phone can't open the laptop's localhost On the phone, localhost means the phone itself Bind the server to 0.0.0.0 and open the laptop's LAN IP and port on the phone
A normal website redirects to 127.0.0.1 An entry in the hosts file points that domain at loopback Remove the line from the hosts file, then run a malware scan

For the phone case you need the laptop's private address, usually 192.168.x.x. The steps to find your computer's IP cover Windows, macOS and Linux.

Frequently asked questions

Is 127.0.0.1 my IP address?

No. 127.0.0.1 is the same internal address on every device in the world, and it only reaches the device using it. It never identifies you to anyone. Your device also has a private address such as 192.168.1.5 at home, and websites see your public address.

Can someone hack me through 127.0.0.1?

No outside computer can send packets to your 127.0.0.1, because routers never forward loopback traffic. The real risks are different. A test server bound to 0.0.0.0 is open to everyone on your network, and malware can edit the hosts file to send real sites to the wrong place.

Is 127.0.0.1 a router login page?

No. 127.0.0.1 always points at the computer you're typing on, so it can't open your router. A router's page sits at its default gateway address, usually something like 192.168.1.1 or 192.168.0.1. The steps to log in to your router show how to find that address.

Can I ping 127.0.0.1 without internet?

Yes. The ping never leaves the computer, so it works with Wi-Fi off and the cable unplugged. A reply only means the operating system's TCP/IP software is working. If it answers but websites don't load, the problem is outside the computer.

What is ::1?

::1 is the IPv6 loopback address, the IPv6 version of 127.0.0.1. Unlike IPv4, which reserves a whole block of about 16.7 million loopback addresses, IPv6 has only this one. When localhost resolves to ::1, programs must listen on IPv6 to answer it.