You type localhost into a browser, a page appears, and nothing about it touches the internet. That is the whole point of localhost: a way for your computer to talk to itself using the same tools it uses to talk to everyone else.
Localhost at a glance
| Item | Value | Where it is defined |
|---|---|---|
| Name | localhost | RFC 6761, section 6.3 |
| IPv4 loopback block | 127.0.0.0/8 (127.0.0.0 to 127.255.255.255) | RFC 6890 and RFC 1122 |
| Usual IPv4 address | 127.0.0.1 | |
| IPv6 loopback address | ::1 (written in full as 0:0:0:0:0:0:0:1) | RFC 4291 |
| Addresses in the IPv4 block | 16,777,216 | Counted from the /8 prefix |
| Reachable from your network or the internet | No | RFC 1122: "MUST NOT appear outside a host" |
| Treated as secure by browsers | Yes, even over http | MDN secure contexts |
What is localhost, exactly?
Two things share the word.
Localhost the name. RFC 6761 reserves the name localhost and says name lookups for it "will always resolve to the respective IP loopback address". Your computer is expected to answer that lookup itself rather than send it to a DNS server on the internet.
Loopback the address. 127.0.0.1 and ::1 are addresses that belong to a virtual network card inside your computer. Anything sent to them is handed straight back to the operating system. RFC 1122 describes the 127 block as the "internal host loopback address" and says such addresses "MUST NOT appear outside a host".
So when a browser opens http://localhost:3000, it looks up the name, gets a loopback address, and connects to port 3000 on the same machine.
Is localhost the same as 127.0.0.1?
Close, but not quite, and the difference is behind a lot of "it works on my machine" puzzles. We tested it on a Windows 10 laptop (build 19045) with Node 24.13.0 on 21 November 2026.
| Test | Result |
|---|---|
Resolve-DnsName localhost (Windows PowerShell) | ::1 (IPv6) and 127.0.0.1 (IPv4) |
ping localhost | Replied from ::1, so IPv6 came first |
ping 127.45.6.7 | Replied. The whole 127 block answers on this machine |
Node dns.lookup("localhost", { all: true }) | ::1 first, then 127.0.0.1 |
Server listening only on 127.0.0.1, opened as http://127.0.0.1:port | Worked |
Same server opened as http://localhost:port from Node 24 | Worked, because Node tried the second address after the first failed |
Same server opened as http://[::1]:port | Connection refused |
The last three rows are the useful part. A server that listens only on 127.0.0.1 is not listening on ::1. Whether localhost works then depends on the client. Node 24 tried the next address when the first one failed, so the request still worked. A client that tries only the first answer gets "connection refused" instead.
If one tool connects and another says "connection refused" to the same localhost address, this is the first thing to check.
How do I make a server answer on both 127.0.0.1 and ::1?
Tell it which address to listen on, or leave the choice to the platform. Three common cases:
| Setting | What it listens on | Reachable from other devices? |
|---|---|---|
127.0.0.1 | IPv4 loopback only | No |
::1 | IPv6 loopback only | No |
localhost | Whatever the name resolves to, often both | No |
| No address at all (Node) | All addresses, IPv6 and usually IPv4 too | Yes, if your firewall allows it |
0.0.0.0 | Every IPv4 address on the computer | Yes, if your firewall allows it |
Node's net documentation explains the "no address" row: if the host is omitted, the server accepts connections "on the unspecified IPv6 address (::) when IPv6 is available", and on most operating systems that also covers IPv4. That is convenient on a laptop at home and a reason to set an explicit loopback address on shared Wi-Fi.
For a server only you should reach, localhost is the friendliest choice, because it follows whatever your system resolves. If a tool still refuses, use 127.0.0.1 on both sides, server and client, and the problem disappears.
What do localhost ports mean?
The number after the colon is the port: which program on your computer should receive the request. Development tools pick a default so you know where to look. These are the defaults each project's own documentation gives:
| Tool | Default address it tells you to open | Source |
|---|---|---|
| Next.js | http://localhost:3000 | Next.js installation docs |
| Ruby on Rails | http://localhost:3000 | Rails getting started guide |
| Angular | http://localhost:4200 | Angular CLI serve docs |
| Flask | http://127.0.0.1:5000 | Flask quickstart |
| Vite | port 5173 | Vite server options |
| Django | port 8000 on 127.0.0.1 | Django admin and runserver docs |
| Jupyter Notebook | http://localhost:8888 | Jupyter docs |
Next.js and Rails share port 3000, so running both at once makes the second one fail or move. Vite's documentation says that if its port is already in use it "will automatically try the next available port", which is why you sometimes find a Vite app on 5174.
Can anyone else reach my localhost?
No. That is a feature, and it is why a development server is safe to run on a laptop in a café.
The flip side catches people out: your phone on the same Wi-Fi cannot open localhost on your laptop either, because on the phone, localhost means the phone. To test a site from another device you need the laptop's local network address (something like 192.168.1.20), and the server has to listen on it. Django's docs say its server "runs on port 8000 on the IP address 127.0.0.1" by default and that you can pass in another IP address and port, which is how you open it to your network on purpose.
Listening on 0.0.0.0 means every address the computer has, including the network one. Only do that on a network you trust.
What does localhost mean inside Docker?
Containers have their own network, so localhost inside a container means the container, not your computer. Docker's documentation says, for example, that a container started with --dns=127.0.0.1 "refers to the container's own loopback address".
That causes a common surprise. A database running on your laptop at localhost:5432 is invisible to an app inside a container that tries localhost:5432, because the app is looking at its own loopback. Docker Desktop provides a special name for this case: its networking guide says host.docker.internal "Resolves to the internal IP address of your host". Point the app at host.docker.internal:5432 instead.
The same idea applies the other way round. A server inside a container that listens only on its own 127.0.0.1 cannot be reached through a published port, so containerised servers are usually told to listen on all addresses inside the container, and the port mapping decides what your computer exposes.
| Where the program runs | What localhost means there |
|---|---|
| Your computer | Your computer |
| A Docker container | That container only |
| A virtual machine | That virtual machine only |
| Your phone | Your phone |
| A remote server you connect to | That server |
How is localhost different from my IP address?
| Address | Who can reach it | Example |
|---|---|---|
| Loopback | Only your own computer | 127.0.0.1, ::1 |
| Local (private) address | Devices on the same home or office network | 192.168.1.20 |
| Public address | The whole internet, through your router | The one shown on our home page |
Your public address is the one websites see. Localhost never appears to them at all. If you want to see which addresses your machine really exposes, our port scanner checks common ports on your public address from the outside.
What to do when localhost does not work
- Make sure the server is running. Read its startup message. It prints the exact address and port it is listening on.
- Use exactly that address. If it says
127.0.0.1:8000, openhttp://127.0.0.1:8000instead oflocalhost, which removes the IPv6 question entirely. - Check whether something else holds the port. On Windows, run
netstat -ano | findstr :3000and match the last number, the process ID, in Task Manager. On macOS and Linux, runlsof -i :3000. The netstat reference lists the switches. - Make the server listen on both address families, or set it to
localhostinstead of127.0.0.1, if a client insists on IPv6. - Check the hosts file if localhost resolves strangely. On Windows it is
C:\Windows\System32\drivers\etc\hosts. On our test machine the localhost lines in that file are commented out and the comment says "localhost name resolution is handled within DNS itself". - Turn off a VPN or proxy if the browser sends localhost traffic away. Some proxy settings need a bypass for localhost.
The one line version
Localhost is your computer's name for itself, and it points to 127.0.0.1 or ::1. Nothing sent there leaves the machine, which makes it the safe place to run things before anyone else sees them. When localhost and 127.0.0.1 behave differently, the reason is almost always IPv6: localhost may try ::1 first, and your server may only be listening on 127.0.0.1. To see the addresses the rest of the world uses for you, check what your IP address reveals or compare IPv4 and IPv6.
