Ports allow a single machine to run multiple network applications simultaneously. A port number (16-bit, 0-65535) identifies the specific application or service on a host.
Port Ranges
| Range | Category | Examples |
|---|---|---|
| 0-1023 | Well-known ports (system services) | HTTP (80), HTTPS (443), SSH (22), DNS (53), SMTP (25) |
| 1024-49151 | Registered ports (specific apps) | MySQL (3306), PostgreSQL (5432), Docker (2375) |
| 49152-65535 | Ephemeral ports (temporary client ports) | Used by browsers, clients |
Important Ports to Know for Interviews
| Port | Protocol | Service |
|---|---|---|
| 20/21 | TCP | FTP (data/control) |
| 22 | TCP | SSH |
| 23 | TCP | Telnet |
| 25 | TCP | SMTP |
| 53 | UDP/TCP | DNS |
| 67/68 | UDP | DHCP |
| 80 | TCP | HTTP |
| 110 | TCP | POP3 |
| 143 | TCP | IMAP |
| 443 | TCP | HTTPS |
| 3306 | TCP | MySQL |
| 6379 | TCP | Redis |
Sockets
A socket is the API endpoint for network communication. It’s identified by:
Socket = IP Address + Port Number
A TCP connection is uniquely identified by a 5-tuple:
(Source IP, Source Port, Destination IP, Destination Port, Protocol)
Socket API Flow (Server)
socket() → bind(local_port) → listen() → accept() → recv()/send() → close()
Socket API Flow (Client)
socket() → connect(server_ip, server_port) → send()/recv() → close()
Q: List important well-known ports.
A: HTTP (80), HTTPS (443), SSH (22), FTP (20/21), SMTP (25), DNS (53), DHCP (67/68), MySQL (3306).
Q: What is a network socket?
A: A software endpoint for network communication — the combination of an IP address and a port number. Like a “software door” with a specific address (house number + room number).
Q: What are ephemeral ports?
A: Temporary ports (49152-65535) assigned by the OS to client applications for outbound connections. When your browser connects to a website, it gets an ephemeral source port that’s released after the session ends.
Q: How does the socket API work?
A: Server: socket() → bind() → listen() → accept() → recv()/send(). Client: socket() → connect() → send()/recv(). Both call close() when done.
Premium Content
Unlock Port Numbers & Sockets and all premium lessons with a subscription.
From ₹199.99/year — See plans