127.0.0.1 — Localhost
127.0.0.1 is the loopback IP address, commonly known as localhost. It always refers to your own computer — any traffic sent to 127.0.0.1 never leaves your machine. Developers use it to test websites, APIs, and applications locally before deploying to production servers.
Access your local server:
http://127.0.0.1
Looking for your router? 127.0.0.1 is NOT a router IP. For router settings, try 192.168.1.1 or 192.168.0.1
What is 127.0.0.1?
The IP address 127.0.0.1 is a special reserved address that represents "this computer." When you type 127.0.0.1 in your browser or use it in code, you're connecting to a server running on your own machine.
Key Facts
- 127.0.0.1 and localhost are identical
- The entire 127.0.0.0/8 range (127.0.0.1 to 127.255.255.255) is reserved for loopback
- Traffic to 127.0.0.1 never reaches the network — it stays on your computer
- Every computer has 127.0.0.1 — it's defined by the operating system
- IPv6 equivalent is
::1
127.0.0.1 vs localhost
| 127.0.0.1 | localhost |
|---|---|
| IP address (numeric) | Hostname (text) |
| Always IPv4 | Can resolve to IPv4 or IPv6 |
| No DNS lookup needed | Requires hosts file lookup |
| http://127.0.0.1 | http://localhost |
In most cases, they work identically. Use whichever you prefer.
Common Localhost Ports
| Address | Service | Used By |
|---|---|---|
| 127.0.0.1:80 | HTTP | Apache, Nginx, XAMPP |
| 127.0.0.1:443 | HTTPS | Secure web servers |
| 127.0.0.1:3000 | Dev Server | React, Node.js, Rails |
| 127.0.0.1:3306 | MySQL | Database server |
| 127.0.0.1:5432 | PostgreSQL | Database server |
| 127.0.0.1:5173 | Vite | Vue, React (Vite) |
| 127.0.0.1:8080 | Alternative HTTP | Tomcat, Jenkins, proxies |
| 127.0.0.1:8888 | MAMP | MAMP default port |
| 127.0.0.1:6379 | Redis | Cache server |
| 127.0.0.1:27017 | MongoDB | NoSQL database |
Start a Local Server
Quick Options (No Install)
# Python 3
python -m http.server 8000
# Open http://127.0.0.1:8000
# Python 2
python -m SimpleHTTPServer 8000
# PHP
php -S localhost:8000
# Node.js (npx)
npx serve
Development Stacks
- XAMPP — Apache + MySQL + PHP (Windows/Mac/Linux)
- MAMP — Apache + MySQL + PHP (Mac)
- WAMP — Apache + MySQL + PHP (Windows)
- Laragon — Modern stack (Windows)
Hosts File
The localhost hostname is defined in your computer's hosts file:
| OS | Hosts File Location |
|---|---|
| Windows | C:\Windows\System32\drivers\etc\hosts |
| Mac/Linux | /etc/hosts |
Default entry: 127.0.0.1 localhost
Why Use Localhost?
- Development — Test websites before going live
- Speed — No network latency, instant responses
- Security — Code never leaves your computer
- Offline — Works without internet connection
- Cost — No hosting fees during development
Troubleshooting
"Connection Refused" Error
No server is running on that port. Solutions:
- Start your web server (Apache, Nginx, Node, etc.)
- Check if you're using the correct port
- Verify the service is actually running
"Address Already in Use"
Another application is using the port:
# Find what's using port 3000
# Mac/Linux
lsof -i :3000
# Windows
netstat -ano | findstr :3000
Test if Localhost is Working
# Ping test (should always work)
ping 127.0.0.1
# Check if port is open
# Mac/Linux
nc -zv 127.0.0.1 80
# Windows PowerShell
Test-NetConnection -ComputerName 127.0.0.1 -Port 80