192.0.2.7203.0.113.100–1023 well-known1024–49151 registered49152–65535 dynamic06553551514515145287160112server44358751514 → 44352871 → 44360112 → 587443 → 52871
Blocks on the laptop: three programs, each with its own portDoors 443 and 587: programs listening on the serverSign: port numbers 0–65535 to scale, in three rangesEnvelopes: one TCP message each, labelled source port → destination portThe laptop (192.0.2.7) runs two browser tabs and a mail app; the server (203.0.113.10) listens on port 443 for the web and 587 for mail. The IP address finds the machine, the port finds the program. Each program gets its own ephemeral port, so each connection has its own 5-tuple: protocol, source IP and port, destination IP and port. The server keeps one socket per connection, and a reply goes back to the one program whose port it names. 192.0.2.7 and 203.0.113.10 are RFC 5737 documentation addresses, the same pair as the HTTPS lesson; the ephemeral port numbers are illustrative.

Port numbers

  1. The laptop has one IP address, 192.0.2.7, but three programs use the network: two browser tabs and a mail app. The IP address finds the machine. A second number, the port, finds the program.

Connections

Delivery

Ports and tuples, field by field

;; step 1/10 · many-programs · local
;; at tab 1 + tab 2 + mail app
laptop 192.0.2.7
  browser tab 1   wants a web page
  browser tab 2   wants another page
  mail app        wants to send mail
server 203.0.113.10
  web server       mail server
the IP address alone cannot say which program a message is for

TCP and UDP count ports separately: TCP port 53 and UDP port 53 are different doors. DNS happens to use both. RFC 6335 sets aside 49152–65535 for dynamic ports, but each OS picks its own ephemeral range; Linux uses 32768–60999 by default. Mail apps hand in mail on port 587 (RFC 6409) or 465 with TLS from the start (RFC 8314). Port 25 is for mail servers passing mail to each other.