Port
The numbered door on a computer that says which program a connection is for.
An IP address gets a packet to the right computer; a port gets it to the right program on that computer. It is a number from 0 to 65535 that both TCP and UDP attach to every packet, next to the address. A server listens on a port, and anything arriving there is handed to the program behind it: a web server, a database, a mail server.
Many ports are conventions everyone follows. 80 is HTTP, 443 is HTTPS, 22 is SSH (remote terminals), 53 is DNS, 25 is email between servers, 5432 is PostgreSQL. When you type https://example.com, the browser silently uses port 443; a URL like http://localhost:3000 is how a developer reaches an app running on port 3000 on their own machine. Your side of the connection also gets a port, a random high number, so the reply knows which browser tab it belongs to.
Ports are also where security starts. A firewall is, at its simplest, a list of which ports are open to whom: a web server exposes 443 and nothing else. An open port is a door that answers; scanning a server's ports is the first thing an attacker (or a security audit) does. Closing everything you do not use is the cheapest hardening there is.
Keep in mind
- IP address = which machine; port = which program on that machine.
- Well-known ports: 80 HTTP, 443 HTTPS, 22 SSH, 53 DNS.
- A firewall decides which ports are reachable from outside.
- The browser hides the port when it is the standard one for the scheme.