The Transport Layer

a port number

If an IP address is like a street address that gets a letter to the right building, a port number is like the apartment number that gets it to the right resident inside. A host runs many network programs at once; the port number says which program a given segment is meant for. It is a 16-bit number, so it ranges from 0 to 65535.

Each transport segment carries two ports: a source port (where replies should come back to) and a destination port (which service to deliver to). Ports come in rough ranges by convention: well-known ports 0 to 1023 are reserved for standard services (HTTP on 80, HTTPS on 443, DNS on 53, SMTP on 25); registered ports 1024 to 49151; and dynamic or ephemeral ports, often 49152 to 65535, which the operating system hands out temporarily to your client programs. So when your browser connects out, it picks an ephemeral source port and aims at destination port 443; the server's reply is addressed back to your ephemeral port.

Why it matters: ports are the key to multiplexing and demultiplexing — they let one IP address host many independent conversations and many different services. A few honest caveats: ports are just numbers and carry no security by themselves; a service can run on any port (port 443 isn't magically HTTPS, it is just the customary place to look), and seeing a port open tells you nothing about whether the software behind it is trustworthy. Firewalls often filter by port, but that is a policy, not proof of safety.

Your browser opens a connection: source 192.168.1.20:51514, destination 93.184.216.34:443. The 443 says 'HTTPS web service'; the 51514 is a throwaway ephemeral port the OS picked so the server's reply finds its way back to this exact tab.

Destination port = which service; source port = where replies return.

A port number is local to a host's transport layer, not a global name. The same number 443 on a million servers refers to a million different listening programs; only the (IP, port) pair is meaningful network-wide.

Also called
port連接埠通訊埠