Port numbers are essential for network communication, allowing multiple services to run on the same server. This guide covers the most important port numbers every developer should know.
Table of Contents
- What Are Port Numbers?
- Port Number Ranges
- Common Web Ports
- Database Ports
- Development Server Ports
- Security Considerations
- Troubleshooting Port Issues
What Are Port Numbers?
Port numbers are 16-bit unsigned integers (0-65535) that identify specific processes or services on a networked computer. They work like apartment numbers in a building - the IP address is the street address, and the port number is the specific apartment.
Format: IP:Port
Examples:
192.168.1.1:80- HTTP web serverexample.com:443- HTTPS secure websitelocalhost:3000- Development server
Why Ports Matter
- Multiple Services: Run web server (80), database (3306), and SSH (22) on same server
- Security: Block or allow specific services through firewall rules
- Development: Test multiple applications simultaneously
- Debugging: Identify which service is causing issues
Key Concept: When you visit https://example.com, your browser automatically connects to port 443 (HTTPS). The port is implicit but always there.
Port Number Ranges
Ports are divided into three categories:
| range | category | usage | examples |
|---|---|---|---|
| 0-1023 | Well-Known Ports | System/Standard services | HTTP (80), HTTPS (443), SSH (22) |
| 1024-49151 | Registered Ports | User/Application services | MySQL (3306), PostgreSQL (5432) |
| 49152-65535 | Dynamic/Private Ports | Temporary/Private use | Randomly assigned by OS |
Well-Known Ports (0-1023)
Reserved for standard services. Require administrative/root privileges to bind.
Registered Ports (1024-49151)
Registered with IANA for specific services. Can be used by normal users.
Dynamic/Private Ports (49152-65535)
Temporary ports assigned by the operating system for client connections.
Common Web Ports
HTTP - Port 80
Protocol: HTTP
Use: Standard web traffic (unencrypted)
Default: Yes (browsers assume :80 for http://)
# Access website on port 80
http://example.com
http://example.com:80 # Explicit port (same as above)
# Start web server
python -m http.server 80 # Requires sudo/admin
node server.js --port 80
HTTPS - Port 443
Protocol: HTTPS
Use: Secure web traffic (encrypted)
Default: Yes (browsers assume :443 for https://)
# Access secure website
https://example.com
https://example.com:443 # Explicit port
# Nginx HTTPS config
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
}
Security: Always use HTTPS (443) for production websites. HTTP (80) sends data in plain text, exposing passwords and sensitive information.
SSH - Port 22
Protocol: SSH (Secure Shell)
Use: Remote server access, file transfers (SFTP)
Security: Encrypted connection
# Connect via SSH
ssh user@example.com
ssh user@example.com -p 22 # Explicit port
# Custom port (more secure)
ssh user@example.com -p 2222
# SFTP (file transfer over SSH)
sftp user@example.com
FTP - Ports 20, 21
Protocol: FTP (File Transfer Protocol)
Ports: 21 (control), 20 (data)
Use: File transfers
Security: ⚠️ Not encrypted (use SFTP or FTPS instead)
# FTP connection (insecure)
ftp example.com
# FTPS (FTP over SSL) - Port 990
ftps example.com 990
DNS - Port 53
Protocol: DNS (Domain Name System)
Use: Domain name resolution
Transport: UDP (primarily), TCP (for large responses)
# Query DNS
nslookup example.com
dig example.com @8.8.8.8
SMTP - Port 25, 587, 465
Protocol: SMTP (Simple Mail Transfer Protocol)
Ports:
- 25: Standard SMTP (often blocked by ISPs)
- 587: SMTP with STARTTLS (recommended)
- 465: SMTPS (SMTP over SSL)
// Node.js email with nodemailer
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587, // STARTTLS
secure: false,
auth: {
user: 'your-email@gmail.com',
pass: 'your-password'
}
});
IMAP - Port 143, 993
Protocol: IMAP (Internet Message Access Protocol)
Ports:
- 143: IMAP (unencrypted)
- 993: IMAPS (IMAP over SSL)
POP3 - Port 110, 995
Protocol: POP3 (Post Office Protocol)
Ports:
- 110: POP3 (unencrypted)
- 995: POP3S (POP3 over SSL)
Database Ports
MySQL/MariaDB - Port 3306
# Connect to MySQL
mysql -h localhost -P 3306 -u root -p
# Connection string
mysql://user:password@localhost:3306/database
// Node.js MySQL connection
const mysql = require('mysql2');
const connection = mysql.createConnection({
host: 'localhost',
port: 3306,
user: 'root',
password: 'password',
database: 'mydb'
});
PostgreSQL - Port 5432
# Connect to PostgreSQL
psql -h localhost -p 5432 -U postgres
# Connection string
postgresql://user:password@localhost:5432/database
MongoDB - Port 27017
# Connect to MongoDB
mongo mongodb://localhost:27017
# With authentication
mongo mongodb://user:password@localhost:27017/database
// Node.js MongoDB connection
const { MongoClient } = require('mongodb');
const client = new MongoClient('mongodb://localhost:27017');
await client.connect();
const db = client.db('mydb');
Redis - Port 6379
# Connect to Redis
redis-cli -h localhost -p 6379
# With password
redis-cli -h localhost -p 6379 -a password
Microsoft SQL Server - Port 1433
# Connection string
Server=localhost,1433;Database=mydb;User Id=sa;Password=password;
Oracle Database - Port 1521
# Connection string
sqlplus user/password@localhost:1521/ORCL
Development Server Ports
Node.js / Express - Port 3000
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.send('Hello World');
});
app.listen(PORT, () => {
console.log(\`Server running on http://localhost:\${PORT}\`);
});
React - Port 3000
# Default React development server
npm start
# Runs on http://localhost:3000
# Custom port
PORT=3001 npm start
Vue.js - Port 8080
# Default Vue development server
npm run serve
# Runs on http://localhost:8080
Angular - Port 4200
# Default Angular development server
ng serve
# Runs on http://localhost:4200
# Custom port
ng serve --port 4201
Next.js - Port 3000
# Default Next.js development server
npm run dev
# Runs on http://localhost:3000
# Custom port
npm run dev -- -p 3001
Python Flask - Port 5000
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World'
if __name__ == '__main__':
app.run(port=5000, debug=True)
# Runs on http://localhost:5000
Django - Port 8000
# Default Django development server
python manage.py runserver
# Runs on http://localhost:8000
# Custom port
python manage.py runserver 8080
Ruby on Rails - Port 3000
# Default Rails server
rails server
# Runs on http://localhost:3000
# Custom port
rails server -p 3001
PHP Built-in Server - Port 8000
# PHP development server
php -S localhost:8000
# Runs on http://localhost:8000
Common Port Conflicts
When Ports Are Already in Use
# Error message
Error: listen EADDRINUSE: address already in use :::3000
# Find what's using the port (Unix/Mac)
lsof -i :3000
netstat -an | grep 3000
# Find what's using the port (Windows)
netstat -ano | findstr :3000
# Kill process on port (Unix/Mac)
kill -9 $(lsof -t -i:3000)
# Kill process on port (Windows)
taskkill /PID <process_id> /F
Running Multiple Servers
# Frontend on 3000
npm start
# Backend on 3001
node server.js --port 3001
# Database on 5432 (PostgreSQL)
# Redis on 6379
# Everything running simultaneously
Frontend: http://localhost:3000
Backend: http://localhost:3001
Database: postgresql://localhost:5432
Redis: redis://localhost:6379
Security Considerations
Block Unused Ports
# Firewall rules (UFW - Ubuntu)
sudo ufw allow 80/tcp # HTTP
sudo ufw allow 443/tcp # HTTPS
sudo ufw allow 22/tcp # SSH
sudo ufw deny 3306/tcp # Block external MySQL access
sudo ufw deny 27017/tcp # Block external MongoDB access
sudo ufw enable
Change Default Ports
Security Tip: Change default SSH port from 22 to a custom port to reduce automated attack attempts.
# /etc/ssh/sshd_config
Port 2222 # Change from default 22
# Restart SSH service
sudo systemctl restart sshd
# Connect with new port
ssh user@example.com -p 2222
Database Security
# Only allow localhost connections
# MySQL config
bind-address = 127.0.0.1
# PostgreSQL pg_hba.conf
host all all 127.0.0.1/32 md5
# Use SSH tunneling for remote database access
ssh -L 3306:localhost:3306 user@remote-server
# Now connect to localhost:3306 on your machine
Port Forwarding
SSH Tunnel
# Forward remote port to local
ssh -L local_port:localhost:remote_port user@server
# Example: Access remote MySQL locally
ssh -L 3306:localhost:3306 user@example.com
# Then connect to localhost:3306
# Forward local port to remote
ssh -R remote_port:localhost:local_port user@server
Nginx Reverse Proxy
# Forward traffic from port 80 to 3000
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Complete Port Reference
Most Common Ports
| Port | Protocol | Service | Security |
|---|---|---|---|
| 20 | FTP | FTP Data | ⚠️ Insecure |
| 21 | FTP | FTP Control | ⚠️ Insecure |
| 22 | SSH | Secure Shell | ✅ Secure |
| 23 | Telnet | Remote Terminal | ⚠️ Insecure |
| 25 | SMTP | Email (Send) | ⚠️ Unencrypted |
| 53 | DNS | Domain Resolution | ✅ Essential |
| 80 | HTTP | Web Traffic | ⚠️ Unencrypted |
| 110 | POP3 | Email (Receive) | ⚠️ Unencrypted |
| 143 | IMAP | Email (Receive) | ⚠️ Unencrypted |
| 443 | HTTPS | Secure Web | ✅ Secure |
| 465 | SMTPS | Secure Email | ✅ Secure |
| 587 | SMTP | Email with TLS | ✅ Secure |
| 993 | IMAPS | Secure Email | ✅ Secure |
| 995 | POP3S | Secure Email | ✅ Secure |
| 1433 | MS SQL | SQL Server | ⚠️ Secure connection |
| 1521 | Oracle | Oracle DB | ⚠️ Secure connection |
| 3000 | Custom | Node.js/React | 🔧 Development |
| 3306 | MySQL | MySQL/MariaDB | ⚠️ Secure connection |
| 4200 | Custom | Angular | 🔧 Development |
| 5000 | Custom | Flask | 🔧 Development |
| 5432 | PostgreSQL | PostgreSQL | ⚠️ Secure connection |
| 6379 | Redis | Redis Cache | ⚠️ Secure connection |
| 8000 | Custom | Django/PHP | 🔧 Development |
| 8080 | HTTP | Alt Web/Vue | 🔧 Development |
| 8443 | HTTPS | Alt Secure Web | ✅ Secure |
| 27017 | MongoDB | MongoDB | ⚠️ Secure connection |
Summary
Understanding port numbers is essential for web development, server configuration, and network troubleshooting. Always use secure protocols (HTTPS, SSH, SFTP) and block unnecessary ports.
Key Takeaways:
✅ Port 80 for HTTP, 443 for HTTPS
✅ Port 22 for SSH remote access
✅ Port 3306 for MySQL, 5432 for PostgreSQL
✅ Development servers: 3000 (Node/React), 8000 (Django), 5000 (Flask)
✅ Always use encrypted connections (HTTPS, SSH, not FTP)
✅ Block database ports from external access
✅ Change default SSH port (22) for better security
✅ Use firewall rules to control port access