Ports and protocols: doors and shared languages
One server can run many services at once. Ports are the numbered doors that keep them apart, and protocols are the agreed languages spoken at each door — like HTTP for the web.
The big idea
A port is a numbered channel a service listens on; a protocol is the agreed set of rules for how two machines exchange messages.
See it in code
A port is a numbered door a service listens on. One port, one service — here's the door secure web traffic waits behind:
# A port is a numbered door a service listens on.
port = 443
service = "HTTPS (secure web)"
print(f"port {port}: {service}")port 443: HTTPS (secure web)
Port 443 is where secure web traffic arrives. A machine has thousands of these numbered doors, and different services wait behind different ones.
Put a few doors together and pair each with the protocol — the agreed language — spoken there. A loop reads them back one at a time:
# A few doors, each with the language spoken there.
doors = {443: "HTTPS", 22: "SSH"}
for port, proto in doors.items():
print(f"door {port} speaks {proto}")door 443 speaks HTTPS door 22 speaks SSH
Two doors, two languages. Real machines keep a whole directory of these — and knowing which doors should be open is where a defender starts.
Common services live on well-known ports. Here's that directory in full — a few port numbers mapped to the protocol each speaks, listed in order. It's what a defender consults to know what should be running:
# Services listen on numbered ports; a protocol is the agreed language.
services = {
80: "HTTP (web)",
443: "HTTPS (secure web)",
22: "SSH (secure login)",
53: "DNS (name lookup)",
}
for port, proto in sorted(services.items()):
print(f"port {port}: {proto}")port 22: SSH (secure login) port 53: DNS (name lookup) port 80: HTTP (web) port 443: HTTPS (secure web)
Port 80 speaks plain HTTP; port 443 speaks encrypted HTTPS — same web, different door and different rules. From a defender's view, knowing which ports should be open is how you spot one that shouldn't be: an unexpected open door is a question worth asking.
Numbered channels plus agreed rules describe far more than networking: radio frequencies (a station per channel, a modulation standard), TV inputs, even function signatures (an agreed way to call). A shared protocol is what lets two systems that never met still understand each other.
Try it yourself
Add more well-known ports (like 25 for email) to the dictionary. Then think like a defender: if you expected only ports 443 and 22 to be open, which entry here would make you investigate?
The common mistake
Confusing a port with a protocol. The port is just a number (the door); the protocol is the language spoken there. A service can speak an unexpected protocol on an unusual port — which is one of the things careful defenders check for.
What it unlocks
Ports and protocols build on how networks work, use dictionaries, and inform what a vulnerability is.