Picture a small company with a web server and a database inside its office network. Between that network and the internet sits one machine, the firewall. Every packet going in or out passes through it, and the firewall decides, packet by packet, whether it may continue. (Addresses and numbers in this lesson are examples, taken from ranges reserved for documentation.)
A basic firewall reads a few fields at the front of each packet: the source and destination IP address, the protocol (TCP or UDP) and the destination port. The port names the service being asked for: 443 is HTTPS, 80 is plain HTTP, 22 is SSH remote login and 5432 is the PostgreSQL database. Rules are written in terms of those fields.
💡Good to know
A port is a numbered door on a machine. Something must be listening behind it for anything to answer.