Localhost
- Pronunciation
- LOH-kul-hohst
In short
Localhost is the hostname for the computer you are using; it resolves to the loopback address 127.0.0.1 (::1 in IPv6), so its traffic stays on the machine.
What is localhost?
Traffic sent to localhost goes into the operating system's network stack and comes straight back out through a virtual loopback interface; it never reaches the network card or the internet. In IPv4 the whole 127.0.0.0/8 range is reserved for loopback, with 127.0.0.1 the standard address, and in IPv6 the loopback address is ::1.
Developers use it constantly. A dev server started with npm run dev is opened at http://localhost:3000, a local database listens on localhost:5432, and tools talk to each other through ports on the same machine. The port number tells the operating system which program should receive the traffic.
Browsers treat localhost as a secure context even over plain HTTP, so features that normally require HTTPS, such as service workers and the clipboard API, work during development. Many tools also distinguish 127.0.0.1 from 0.0.0.0: a server bound to 127.0.0.1 accepts only local connections, while one bound to 0.0.0.0 listens on every network interface.
A common misconception is that localhost inside a Docker container means your computer. Each container has its own network namespace, so localhost there is the container itself; to reach a service on the host, use the address Docker provides, such as host.docker.internal, or put both services on the same Docker network.
Key takeaways
- Localhost is the name for your own machine, the loopback address.
- It resolves to 127.0.0.1 in IPv4 and ::1 in IPv6.
- Loopback traffic never leaves the computer.
- Ports separate programs, as in localhost:3000 for a dev server.
- Inside a container, localhost is the container, not the host.
Example
import http from "node:http";
const handler = (req, res) => res.end("Hello from this machine\n");
// Only reachable from this computer
http.createServer(handler).listen(3000, "127.0.0.1");
// Reachable from other devices on the network too (e.g. a phone on the same Wi-Fi)
http.createServer(handler).listen(3001, "0.0.0.0");
// curl http://localhost:3000 → works
// curl http://<your-LAN-IP>:3000 → refused; :3001 worksReaders ask
What is the difference between localhost and 127.0.0.1?
Localhost is a name and 127.0.0.1 is an address. The name usually resolves to 127.0.0.1, and on many systems also to ::1, the IPv6 loopback, which is why a server listening only on IPv4 can occasionally behave differently.
Can other people access my localhost?
No. Loopback traffic stays inside your machine. To let others reach a local server, it must listen on a network interface and be reachable through your network, or be exposed through a tunneling tool.
What does localhost:3000 mean?
Port 3000 on your own machine. Development servers commonly use ports such as 3000, 5173 or 8080, and the port tells the system which program should handle the request.
See also
- IP AddressNetworking, p. 10An IP address is a numeric label assigned to each device on a network so that data can be routed to it, much like a postal address for a house.
- PortNetworking, p. 22A port is a number from 0 to 65535 that identifies a specific program or service on a device, so traffic reaching an IP address gets to the right application.
- IPv4Networking, p. 11IPv4 is the internet's original addressing system, using 32-bit addresses written as four numbers such as 192.168.1.10, allowing about 4.3 billion addresses.
- IPv6Networking, p. 12IPv6 is the newest version of the Internet Protocol, using 128-bit addresses that give every device a unique address and replace the exhausted IPv4 pool.
- Web ServerBackend & APIs, p. 46A web server is software, or the machine running it, that accepts HTTP requests from browsers and other clients and responds with pages, files, or data.
- DockerDevOps & Cloud, p. 17Docker is an open-source platform for packaging an application and everything it needs into a container that runs the same way on any machine.
Spotted a mistake or something missing on this page?Suggest an edit