# Ports, sockets and the five-tuple: how a host and every box in the path tell one conversation from another

> An address gets a packet to a machine; a port gets it to a program; and five fields together, the protocol, two addresses and two ports, name one conversation for the host and for every box that has to follow it. This part opens NetFun III: it reads the definitions in the standards that wrote them, from RFC 147 in 1971 to RFC 9293 and the registry IANA updated this week, works out by hand a laptop's five-tuples, the same flows through a translator, the arithmetic of the ephemeral range and TIME-WAIT, and the hash that pins a flow to one path, and ends with Brazil's port 25 management. After it you can read a socket table, predict when a client or a translator runs out of ports, and explain why a firewall, a load balancer and an ECMP router all key on the same five numbers.

Source: https://ronutz.com/en/learn/ports-sockets-and-the-five-tuple  
Updated: 2026-11-23  
Related tools: https://ronutz.com/en/tools/tcpdump-filter-explainer, https://ronutz.com/en/tools/cgn-port-blocks, https://ronutz.com/en/tools/flow-path-reasoner, https://ronutz.com/en/tools/python-playground

---

NetFun II ended with a packet that reached the right machine: an address plan, a routing table, the [longest match](https://ronutz.com/en/learn/static-routes-and-longest-match) that chose a next hop. A machine, though, runs many programs at once, and a busy server holds thousands of conversations with the same clients. NetFun III, the third level of the network fundamentals, is about what happens above the address: the transport that names conversations, the tunnels that wrap them, the proxies and load balancers that stand in the middle, and the planes that watch it all. This first part is the thread through every module that follows. It reads how a port, a socket and a connection are defined, by the documents that defined them; works out by hand which five numbers identify each conversation on a laptop, what a translator does to them, how many of them a client or a proxy can hold, and how a router uses them to keep a flow on one path; and closes with the Brazilian decision that turned one port number into national policy. After it you can read a socket table, predict when a host or a translator runs out of source ports, and say why a firewall, a load balancer and an equal-cost router all key on the same five fields.

## An address names a machine; a port names a conversation

The Internet Protocol (IP) carries a datagram to a host and stops there. Which program on the host should receive it is the transport's job, and the transports of the internet do it with two 16-bit numbers in their headers. The Transmission Control Protocol (TCP) header opens with "Source Port: 16 bits" and "Destination Port: 16 bits" ([RFC 9293, section 3.1](https://www.rfc-editor.org/rfc/rfc9293.html#section-3.1)); the User Datagram Protocol (UDP) header has the same two fields in the same place, with the difference that its source port is "an optional field" and "If not used, a value of zero is inserted" ([RFC 768](https://www.rfc-editor.org/rfc/rfc768.html)). Sixteen bits give 65,536 values, 0 to 65,535, in each protocol.

The word is older than either protocol. On 7 May 1971, Joel M. Winett of the Massachusetts Institute of Technology's Lincoln Laboratory wrote to the Network Socket Committee of the ARPANET, the network of the Advanced Research Projects Agency (ARPA), that "A socket is defined to be the unique identification to or from which information is transmitted in the network", a 32-bit number "with even sockets identifying receiving sockets and odd sockets identifying sending sockets", and that "A socket has been defined to be the identification of a port for machine to machine communication through the ARPA network" ([RFC 147](https://www.rfc-editor.org/rfc/rfc147.html)). A port was the program's door; the socket was the network's name for it.

TCP's specification of September 1981 fixed the modern meaning. A host provides a set of ports, and "Concatenated with the network and host addresses from the internet communication layer, this forms a socket. A pair of sockets uniquely identifies each connection" ([RFC 793, section 1.5](https://www.rfc-editor.org/rfc/rfc793.html#section-1.5)). The same section draws the consequence that matters to every server: "a socket may be simultaneously used in multiple connections". RFC 9293, which obsoleted RFC 793 in August 2022 and is the TCP standard today, keeps both ideas: a socket is "An address that specifically includes a port identifier, that is, the concatenation of an Internet Address with a TCP port", and "A connection is defined by a pair of sockets" ([RFC 9293, section 3.4.1 and the glossary](https://www.rfc-editor.org/rfc/rfc9293.html#section-3.4.1)).

So a web server's socket, 203.0.113.80 port 443, takes part in every connection to it at once. What keeps those connections apart is the other socket of each pair: the client's address and port. Programmers meet the same word as an operating system object, the handle a program reads and writes, which [Python sockets for network engineers](https://ronutz.com/en/learn/python-sockets-for-network-engineers) works through call by call; this part stays on the wire.

## The five-tuple: the name every box uses

A pair of sockets is two addresses and two ports. Add the protocol, because TCP port 443 and UDP port 443 are different doors, and you have five fields. RFC 6437, the IPv6 flow label specification of November 2011, states the convention plainly: "Traditionally, flow classifiers have been based on the 5-tuple of the source address, destination address, source port, destination port, and the transport protocol type", and "A typical definition of a flow for this purpose is any set of packets carrying the same 5-tuple `{dest addr, source addr, protocol, dest port, source port}`" ([RFC 6437, sections 1 and 3](https://www.rfc-editor.org/rfc/rfc6437.html)). RFC 6056, on port randomization, uses the same five fields to name "the transport protocol instance" ([RFC 6056, section 1](https://www.rfc-editor.org/rfc/rfc6056.html#section-1)), and RFC 7424, on load sharing over parallel links, identifies flows by "The 5-tuple in the packet header (IP source address, IP destination address, transport protocol source port number, transport protocol destination port number, and IP protocol)" ([RFC 7424, appendix A](https://www.rfc-editor.org/rfc/rfc7424.html#appendix-A)).

The protocol field is the IP header's number for the transport, from the Internet Assigned Numbers Authority (IANA) registry of protocol numbers: 6 for TCP (its reference is now RFC 9293), 17 for UDP, 1 for the Internet Control Message Protocol (ICMP), 58 for ICMP for IPv6, 33 for the Datagram Congestion Control Protocol (DCCP) and 132 for the Stream Control Transmission Protocol (SCTP) ([IANA, Assigned Internet Protocol Numbers](https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml)). RFC 768 had already given UDP's: "This is protocol 17 (21 octal)".

Every box that must recognize a conversation, rather than just forward a packet, keys on these five numbers. A [stateful firewall](https://ronutz.com/en/learn/packet-filters-stateful-inspection-and-deep-packet-inspection) looks each one up in its connection table; a translator rewrites two of them and remembers how; a load balancer hashes them or opens a second connection with a new set; an equal-cost router hashes them to choose a path. RFC 3234, the taxonomy of these devices, gives them their name: "A middlebox is defined as any intermediary device performing functions other than the normal, standard functions of an IP router on the datagram path between a source host and destination host", a word it credits to Lixia Zhang ([RFC 3234, section 1.1](https://www.rfc-editor.org/rfc/rfc3234.html#section-1.1)). NetFun III is, in a sense, a tour of the middleboxes, and this is the key they all share.

### Worked example: one laptop, five conversations

A laptop at 192.0.2.10 (an address from the blocks RFC 5737 reserves for documentation) resolves a name, opens a page with two parallel connections, upgrades to HTTP/3 (version 3 of the Hypertext Transfer Protocol), and keeps a Secure Shell (SSH) session open. Written out, the five-tuples it holds at one moment are:

| Flow | Protocol | Source address | Source port | Destination address | Destination port | What it is |
|---|---|---|---|---|---|---|
| A | UDP (17) | 192.0.2.10 | 51734 | 198.51.100.53 | 53 | a Domain Name System (DNS) query |
| B | TCP (6) | 192.0.2.10 | 60412 | 203.0.113.80 | 443 | the first HTTPS (HTTP Secure) connection |
| C | TCP (6) | 192.0.2.10 | 49377 | 203.0.113.80 | 443 | a second, parallel HTTPS connection |
| D | UDP (17) | 192.0.2.10 | 57290 | 203.0.113.80 | 443 | HTTP/3, carried by QUIC over UDP |
| E | TCP (6) | 192.0.2.10 | 52018 | 198.51.100.22 | 22 | an SSH session |

Read it as a box in the path would.

- **B and C** share four fields and differ only in the source port. That one number is the whole difference between two connections, and it is why the client side needs a fresh port for every connection to the same server.
- **C and D** go to the same address and the same destination port, and are still unrelated: the protocol differs. IANA's registry treats each transport as its own number space, listing "https" for TCP and for UDP as separate rows ([IANA, Service Name and Transport Protocol Port Number Registry](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml)).
- **The server's view** of flow B is the same five numbers with source and destination swapped: from 203.0.113.80 port 443 to 192.0.2.10 port 60412. A stateful device has to recognize both directions as one conversation, which is why connection tables store a flow once and match it either way round.
- **The destination ports** say what the client expected to find; they prove nothing about what answered. RFC 6335 warns that "port numbers have meaning only for the two endpoints involved in a connection, and drawing conclusions about the service that generated a given flow based on observed port numbers is not always reliable" ([RFC 6335, section 7.2](https://www.rfc-editor.org/rfc/rfc6335.html#section-7.2)).

The source ports in the table look random because a good stack makes them so, for a reason the next section gives.

## Who chooses which port

### The server's port: the registry

Clients find a service because its port is agreed in advance. IANA keeps that agreement in the Service Name and Transport Protocol Port Number Registry, whose procedures are RFC 6335 (August 2011, Best Current Practice 165). It divides the 16-bit space into three ranges ([RFC 6335, section 6](https://www.rfc-editor.org/rfc/rfc6335.html#section-6)):

| Range | Name in RFC 6335 | Also called | Assigned how |
|---|---|---|---|
| 0 to 1023 | System Ports | Well Known Ports | by IANA, under "IETF Review" or "IESG Approval" (the Internet Engineering Task Force, IETF, and its steering group, the IESG) |
| 1024 to 49151 | User Ports | Registered Ports | by IANA, also by "Expert Review" |
| 49152 to 65535 | Dynamic Ports | Private or Ephemeral Ports | never assigned |

The procedures column is the registry page's own wording, which also names the experts who review requests for TCP and UDP ([IANA, the registry page, last updated 19 November 2026](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml)). RFC 6335 recorded that, when it was written, "approximately 76% of the TCP and UDP System Ports were assigned, and approximately 9% of the User Ports". Counted by hand from the registry's comma-separated copy read on 23 November 2026, the numbers have moved: 686 of the 1,024 System Ports carry at least one named assignment (67.0%), and 5,419 of the 48,128 User Ports (11.3%); the Dynamic Ports have none, as designed. (The count treats a port as assigned when any protocol row for it carries a service name, and leaves out rows marked Reserved or Unassigned; the 2011 figure may have been counted differently, so the comparison shows a direction, not a rate.) The registry is alive: its first lines record port 2 "De-assigned on 2025-02-13", previously compressnet.

RFC 6335 also changed how numbers are handed out: IANA "will begin assigning port numbers for only those transport protocols explicitly included in an assignment request", ending "the long-standing practice of automatically assigning a port number to an application for both TCP and UDP" ([RFC 6335, section 7.2](https://www.rfc-editor.org/rfc/rfc6335.html#section-7.2)). That is why the registry today shows, for example, IMAP (Internet Message Access Protocol) on TCP 143 with UDP 143 marked Reserved, while older services such as DNS on 53 and the Network Time Protocol (NTP) on 123 keep both rows.

A few rows read from the registry on 23 November 2026, because an engineer meets them every day:

| Port | Protocol in the registry | Service name | Note |
|---|---|---|---|
| 22 | TCP, UDP, SCTP | ssh | The Secure Shell (SSH) Protocol |
| 25 | TCP, UDP | smtp | Simple Mail Transfer |
| 53 | TCP, UDP | domain | Domain Name Server |
| 123 | TCP, UDP | ntp | Network Time Protocol |
| 443 | TCP, UDP, SCTP | https | "http protocol over TLS/SSL": Transport Layer Security, and Secure Sockets Layer before it |
| 465 | TCP | urd and submissions | two names on one number: "URL Rendezvous Directory for SSM" (Uniform Resource Locator; source-specific multicast) and "Message Submission over TLS protocol" |
| 514 | TCP: shell; UDP: syslog | | the same number, different services per protocol |
| 587 | TCP, UDP | submission | Message Submission |
| 853 | TCP, UDP | domain-s | DNS over TLS on TCP; over Datagram TLS (DTLS) or QUIC on UDP |
| 3389 | TCP, UDP | ms-wbt-server | "MS WBT Server", Microsoft's remote desktop |

Port 514 shows why the protocol belongs in the tuple: on TCP it is "shell", on UDP "syslog". Port 465 shows that even the registry keeps history in layers; we return to it in the Brazilian section.

A registration is a convention, not a guarantee. RFC 6335 says so in its security section: "the fact that network traffic is flowing to or from an assigned port number does not mean that it is "good" traffic, or even that it is used by the assigned service", and administrators "should choose how to configure their systems based on their knowledge of the traffic in question, not based on whether or not there is an assigned service name or port number" ([RFC 6335, section 9](https://www.rfc-editor.org/rfc/rfc6335.html#section-9)).

On a Linux host the low range is also a privilege boundary: "Privileged ports require root or CAP_NET_BIND_SERVICE in order to bind to them", the first unprivileged port is the per-namespace setting `ip_unprivileged_port_start`, "Default: 1024", and setting it to 0 disables privileged ports altogether ([Linux kernel documentation, IP Sysctl](https://docs.kernel.org/networking/ip-sysctl.html)). The rule protects the local host's numbers and says nothing about the remote end.

### The client's port: the ephemeral range

The client almost never chooses its port. RFC 6056 (January 2011, Best Current Practice 156) describes the usual arrangement: the client's address and port "are normally left unspecified by the client application and thus are chosen automatically by the client networking stack. Ports chosen automatically by the networking stack are known as ephemeral ports" ([RFC 6056, section 1](https://www.rfc-editor.org/rfc/rfc6056.html#section-1)). The one rule is uniqueness: "the selection of ephemeral port numbers must result in a unique five-tuple" ([RFC 6056, section 2.2](https://www.rfc-editor.org/rfc/rfc6056.html#section-2.2)).

The other rule is security. Attacks that inject segments into a connection or reset it from outside "rely on the attacker's ability to guess or know the five-tuple"; the server's address and port are public, often the client's address too, so the ephemeral port is the part left to guess (RFC 6056, section 1). RFC 6056 therefore recommends choosing it unpredictably, and from as wide a range as possible: "ephemeral port selection algorithms should use the whole range 1024-65535", and "SHOULD use the largest possible port range, since this reduces the chances of an off-path attacker of guessing the selected port numbers" ([RFC 6056, section 3.2](https://www.rfc-editor.org/rfc/rfc6056.html#section-3.2)).

Implementations chose differently:

| System | Default ephemeral range | Ports in it | Source |
|---|---|---|---|
| RFC 6056's recommendation | 1024 to 65535 | 64,512 | RFC 6056, section 3.2 |
| IANA Dynamic Ports | 49152 to 65535 | 16,384 | RFC 6335, section 6 |
| Linux (`net.ipv4.ip_local_port_range`) | 32768 to 60999 | 28,232 | Linux kernel documentation, IP Sysctl |
| Windows since Vista and Server 2008 | 49152 to 65535 | 16,384 | Microsoft Learn |
| Windows before Vista | 1025 to 5000 | 3,976 | Microsoft Learn |

Microsoft's note says it moved Windows "To comply with Internet Assigned Numbers Authority (IANA) recommendations", that the range is set separately for TCP and UDP, and that `netsh int ipv4 show dynamicport tcp` shows it ([Microsoft Learn, the default dynamic port range for TCP/IP](https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/default-dynamic-port-range-tcpip-chang)). The Linux documentation adds that the two numbers should preferably have different parity and that the range must start at or above `ip_unprivileged_port_start` (Linux kernel documentation, IP Sysctl). The counts in the third column are inclusive: 60,999 − 32,768 + 1 = 28,232.

## Worked example: how many conversations fit

The ephemeral range is a budget, and it is spent per destination. Take one client address talking to one server socket, 203.0.113.80 port 443, over TCP. Four of the five fields are fixed, so each simultaneous connection needs a different source port.

1. **Simultaneous connections.** A Linux client with the default range can hold at most 28,232 connections to that one server socket; a Windows client, 16,384. To a *different* server socket the whole budget is available again, because the five-tuple differs in another field.
2. **Connections that have closed.** The end that closes first does not free its port at once. RFC 9293 says it "MUST linger in the TIME-WAIT state for a time 2xMSL (Maximum Segment Lifetime)" ([RFC 9293, section 3.6.1](https://www.rfc-editor.org/rfc/rfc9293.html#section-3.6.1)), and "For this specification the MSL is taken to be 2 minutes", "an engineering choice" ([RFC 9293, section 3.4.2](https://www.rfc-editor.org/rfc/rfc9293.html#section-3.4.2)). With the specification's numbers, a closed connection holds its five-tuple for 2 × 120 = 240 seconds. The standard is explicit about the purpose: "the TIME-WAIT state limits the rate of connection reuse" (section 3.4.1).
3. **The sustainable rate.** If the client closes first and every connection is short, the steady state is reached when the ports leaving TIME-WAIT equal the ports being used: 28,232 ports ÷ 240 seconds ≈ 117.6 new connections a second, to that one server socket, from that one address. With the Windows range, 16,384 ÷ 240 ≈ 68.3 a second.

Operating systems set their own TIME-WAIT duration and offer ways to reuse ports early, so the real figures differ from host to host; the arithmetic shows the shape of the limit, not any product's number. The shape is what matters for the boxes in the middle. A proxy or a source network address translator (SNAT) opens connections to a few servers from a few addresses on behalf of many clients, so it reaches this ceiling long before any client does. [SNAT and the return-traffic problem](https://ronutz.com/en/learn/bigip-snat-and-return-traffic) shows the ceiling on a BIG-IP, and [port blocks and port sets](https://ronutz.com/en/learn/port-blocks-and-port-sets) does the arithmetic for carrier-grade translation, with the [port block calculator](https://ronutz.com/en/tools/cgn-port-blocks) for carrier-grade NAT (CGN) to try it.

## Worked example: the same flows through a translator

Network Address Port Translation (NAPT), the port-rewriting form of network address translation (NAT), is the form of translation in nearly every home router and enterprise edge. RFC 3022 (January 2001) describes it as mapping "tuples of the type (local IP addresses, local TU port number) to tuples of the type (registered IP address, assigned TU port number)", TU standing for the transport layer's unit, TCP or UDP ([RFC 3022, section 2.2](https://www.rfc-editor.org/rfc/rfc3022.html#section-2.2)). Put the laptop behind a translator whose outside address is 198.51.100.7, and add a second inside host, 192.0.2.11, which happens to pick the same source port as flow B for its own connection to the same server.

| Inside five-tuple (protocol, inside source, destination) | Outside five-tuple after translation | What the translator remembers |
|---|---|---|
| TCP, 192.0.2.10:60412 → 203.0.113.80:443 | TCP, 198.51.100.7:40001 → 203.0.113.80:443 | 40001 belongs to 192.0.2.10:60412 |
| TCP, 192.0.2.11:60412 → 203.0.113.80:443 | TCP, 198.51.100.7:40002 → 203.0.113.80:443 | 40002 belongs to 192.0.2.11:60412 |
| UDP, 192.0.2.10:51734 → 198.51.100.53:53 | UDP, 198.51.100.7:40003 → 198.51.100.53:53 | 40003 (UDP) belongs to 192.0.2.10:51734 |

The outside port numbers are chosen for readability; a real translator picks them by its own policy. Three things follow.

- The two inside connections have identical outside fields except the outside port, so the translator *must* change at least one source port: from the server's side, the outside source port is now the only thing that tells the two hosts apart. The address-and-port pair, not the address, is the identity of a subscriber behind shared addresses, which is why attribution of a connection to a person needs the source port and an accurate time; [carrier-grade NAT (CGNAT), address sharing and attribution](https://ronutz.com/en/learn/cgnat-address-sharing-and-attribution) follows that thread into law, including Brazil's.
- The translator's table is keyed on five-tuples in both directions: a reply from 203.0.113.80:443 to 198.51.100.7:40002 is mapped back to 192.0.2.11:60412. A reply that matches no entry has nowhere to go.
- UDP has no handshake or close to tell the translator when a flow ends, only silence, so a mapping lives as long as its timer. RFC 4787 requires that "A NAT UDP mapping timer MUST NOT expire in less than two minutes" and recommends "A default value of five minutes or more" ([RFC 4787, REQ-5](https://www.rfc-editor.org/rfc/rfc4787.html#section-4.3)). The [next part](https://ronutz.com/en/learn/udp-the-protocol-that-is-a-header) comes back to what that means for applications.

How a translator allocates ports, how it behaves towards different destinations, and how to see its table are the subject of [NAT explained](https://ronutz.com/en/learn/nat-explained); the point here is narrower: translation is an operation on the five-tuple, and every rule about it is a rule about which of the five fields change.

## Worked example: one flow, one path

When a router has several equal-cost next hops for a destination, it must spread traffic without splitting a TCP connection across paths of different delay, which would deliver its segments out of order. RFC 2992 (November 2000) analyses the common method, which it calls hash-threshold: "The router first selects a key by performing a hash (e.g., CRC16) over the packet header fields that identify a flow. The N next-hops have been assigned unique regions in the key space" ([RFC 2992, section 1](https://www.rfc-editor.org/rfc/rfc2992.html#section-1)). CRC16 is a 16-bit cyclic redundancy check, so the key space runs from 0 to 65,535.

Its own example uses four next hops and equal regions of 65,536 ÷ 4 = 16,384 keys. Written out:

| Next hop | Region of the key space |
|---|---|
| 1 | 0 to 16,383 |
| 2 | 16,384 to 32,767 |
| 3 | 32,768 to 49,151 |
| 4 | 49,152 to 65,535 |

Suppose the hash of flow B's five-tuple gives the key 40,000 and the hash of flow C's gives 9,000 (illustrative values; the real ones depend on the function and the fields a vendor feeds it). Flow B goes to next hop 3 and flow C to next hop 1. Every later packet of flow B carries the same five fields, produces the same key and takes the same path, so the connection keeps its order; flows B and C, which differ only in the source port, may take different paths and share the load. RFC 2992 puts the property in one sentence: "As long as the region boundaries remain unchanged the same next-hop will be chosen for a given flow" ([RFC 2992, section 2.2](https://www.rfc-editor.org/rfc/rfc2992.html#section-2.2)).

The boundaries move when a next hop is added or removed, and some flows change path. RFC 2992 computes the cost for five next hops when the third is deleted: the remaining regions grow and shift, and "the total disruption is 1/5*(1/4 + 1/2 + 1/2 + 1/4) or 3/10" of all flows. The [part on health checks and persistence](https://ronutz.com/en/learn/health-checks-persistence-and-the-two-questions) meets the same arithmetic in load balancers, where a server leaving a pool moves clients that were not on it, unless the hash is consistent.

Two limits are worth knowing. A fragment after the first carries no transport header, so the ports are not there to hash, and an encrypted tunnel hides the inner five-tuple behind the outer one; RFC 6437 names both cases ("some of these fields may be unavailable due to either fragmentation or encryption") and allows a forwarding node to "use the 2-tuple when the complete 5-tuple" is not available ([RFC 6437, sections 1 and 3](https://www.rfc-editor.org/rfc/rfc6437.html)). And a five-tuple says nothing about size: in the traffic RFC 7424 analysed, fewer than about 2% of flows carried about 30% of the volume ([RFC 7424, appendix A](https://www.rfc-editor.org/rfc/rfc7424.html#appendix-A)), so an even spread of flows is not an even spread of bytes.

The same hash runs inside load balancers by default. Google Cloud's documentation, read today, says that "By default, all Google Cloud load balancers select backends by using a five-tuple hash", listing the packet's source address, source port "(if present in the packet's header)", destination address, destination port and protocol ([Google Cloud, Backend services overview, session affinity](https://cloud.google.com/load-balancing/docs/backend-service)).

## When the five-tuple is not enough

The five-tuple names a conversation only while its fields stay put. Two common cases break that assumption.

- **The client's address changes.** A phone that moves from Wi-Fi to a mobile network gets a new address, and every TCP connection it had is, by definition, gone: a new address is a new socket and a new pair. QUIC was designed around this. Its connections carry connection IDs, whose "primary function" is "to ensure that changes in addressing at lower protocol layers (UDP, IP) do not cause packets for a QUIC connection to be delivered to the wrong endpoint" ([RFC 9000, section 5.1](https://www.rfc-editor.org/rfc/rfc9000.html#section-5.1)). A middlebox that tracks QUIC by five-tuple sees a migrated connection as a new flow; [QUIC streams, loss and migration](https://ronutz.com/en/learn/quic-streams-loss-and-migration) explains what the transport promises in that case.
- **A box in the middle terminates the connection.** A full proxy holds two connections with two unrelated five-tuples, one with the client and one with the server, and the server sees the proxy's address and port. [The TCP proxy](https://ronutz.com/en/learn/tcp-proxy-layer-4) explains the split and the headers that carry the original client across it.

## Reading sockets on a host

Before any capture, the host already knows its five-tuples. On Linux, `ss` is the tool its manual calls "another utility to investigate sockets" ([Linux man-pages, ss(8)](https://man7.org/linux/man-pages/man8/ss.8.html)). The options this part needs are `-t` and `-u` for TCP and UDP, `-a` for all sockets including listening ones, `-l` for listening only, `-n` for numbers instead of service names, and `-p` for the owning process. Filters follow the same vocabulary as the five-tuple: a state (`established`, `time-wait`, `close-wait` and the other TCP states) and expressions on `dport` and `sport`. The manual's own example, `ss -o state established '( dport = :ssh or sport = :ssh )'`, shows "all established ssh connections" (ss(8), usage examples).

Three readings cover most first questions:

- `ss -tln` lists the listening TCP sockets with numeric ports: the server sockets, each with one address and one port and no peer.
- `ss -tn state established '( dport = :443 )'` lists the client side of this host's HTTPS connections; each line is one five-tuple, local address and port, peer address and port, protocol implied by `-t`.
- `ss -tn state time-wait` counts the five-tuples still held after closing, which is the second step of the budget above, measured.

On Windows, `netstat -an` lists the same pairs, and the range they draw from is in the `netsh` command quoted earlier. For the wire itself, the [tcpdump filter explainer](https://ronutz.com/en/tools/tcpdump-filter-explainer) reads capture filters written in the same terms (`host`, `port`, `tcp`, `udp`), and the [flow path reasoner](https://ronutz.com/en/tools/flow-path-reasoner) follows one flow through the boxes in its path.

## The Brazilian angle: when one port number became policy

Brazil turned a single destination port into a national programme. The problem, as the Brazilian Internet Steering Committee (Comitê Gestor da Internet no Brasil, CGI.br) and its incident response team, CERT.br (Centro de Estudos, Resposta e Tratamento de Incidentes de Segurança no Brasil), described it, was spam sent by infected home computers straight to recipients' mail servers on TCP port 25. In a presentation to the committee on 11 September 2012, Cristine Hoepers of CERT.br summarized a CGI.br study with sensors in five cable and digital subscriber line (DSL) operators: more than 90% of the observed traffic was attempts to connect directly to the recipient's mail server, about 99.9% of the spam that tried to pass through the sensors came from outside Brazil, and more than 90% was destined for networks outside the country; Brazilian address blocks were landing on blocklists, and each spam crossed the international links twice ([CERT.br, Internet Security Booklet and Port 25 Management (in Portuguese), 11 September 2012](https://www.cert.br/palestras/certbr-cgibr2012-09-11.pdf)).

The remedy was a separation the standards already offered. Mail *submission* from a user's program to its own provider has its own protocol and port, RFC 6409's Message Submission on port 587, distinct from *transport* between servers on port 25 ([RFC 6409](https://www.rfc-editor.org/rfc/rfc6409.html)). Antispam.br, the site of NIC.br (Núcleo de Informação e Coordenação do Ponto BR, the committee's executive arm) that documents the programme, defines "port 25 management" (Gerência de Porta 25; our translation here and below) as the set of policies and technologies, deployed in end-user or residential networks, that "seeks to separate the functions of message submission from those of message transport between servers" ([Antispam.br, What is port 25 management (in Portuguese)](https://www.antispam.br/admin/porta25/definicao/)).

The record, from the primary documents:

| Date | Step | Source |
|---|---|---|
| 24 April 2009 | Resolution CGI.br/RES/2009/002/P recommends that e-mail providers offer authenticated submission and that connectivity providers for residential, dynamically addressed users restrict direct delivery to port 25 | [CGI.br, Resolution CGI.br/RES/2009/002/P (in Portuguese)](https://www.cgi.br/resolucoes/documento/2009/002/) |
| April 2011 | The cooperation agreement approved by the National Telecommunications Agency (Agência Nacional de Telecomunicações, Anatel) | CERT.br, 11 September 2012 |
| October 2011 | Endorsement by the Ministry of Justice's consumer protection department (DPDC) | CERT.br, 11 September 2012 |
| 2011 | The agreement between CGI.br and NIC.br, Anatel, the operators' association SindiTelebrasil (Sindicato Nacional das Empresas de Telefonia e de Serviço Móvel Celular e Pessoal) and associations of access providers; the text is dated "São Paulo, 15 July 2011", while CERT.br's 2012 presentation gives the signature as 11 November 2011 | [Cooperation Agreement to Implement the Port 25 Management Recommendation (in Portuguese)](https://www.antispam.br/porta25/brasil/acordo-cgibr-anatel-porta25.pdf); CERT.br, 11 September 2012 |
| 2012 | Implementation by the operators, "during the year 2012" | CERT.br, 11 September 2012 |

The agreement is precise about ports. Connectivity providers were to implement the restriction in those networks "by blocking outbound traffic to Port 25/TCP", and otherwise "shall neither interfere with nor block outbound traffic to ports related to message submission protocols"; the block was to start gradually only once at least 90% of the users of the e-mail providers concerned had migrated to submission or webmail (Cooperation Agreement, items 2.1.1, 2.2 and 2.3). CERT.br's presentation shows the resulting picture: home users send on 587 (or 465) and through webmail on 80, servers keep talking to each other on 25, and malware on a home computer can no longer deliver directly.

Two details tie this back to the registry. Antispam.br's definition page, written before 2018, says that port 465 for submission "never became a standard" and was considered deprecated; RFC 8314 of January 2018 later standardized submission over implicit Transport Layer Security (TLS) on port 465, and the registry now lists "submissions" beside the older "urd" on that number ([RFC 8314](https://www.rfc-editor.org/rfc/rfc8314.html); IANA registry). And the dates disagree between two primary documents, July or November 2011 for the signature; both are given above rather than one being chosen. The attribution question that shared addresses raise, the source port that Brazilian logging must keep, is in [the CGNAT part of NetFun II](https://ronutz.com/en/learn/cgnat-address-sharing-and-attribution).

## This series, in order

This part opens NetFun III, the third level of Network Fundamentals. The five-tuple is the thread: the transport names it, a tunnel hides it behind another, a proxy replaces it, a flow record counts it, and a capture filters on it. The five modules follow that order.

1. **Transport.** This part; [UDP: the protocol that is a header](https://ronutz.com/en/learn/udp-the-protocol-that-is-a-header); [the TCP connection lifecycle](https://ronutz.com/en/learn/tcp-connection-lifecycle); [TCP flow and congestion control in one sitting](https://ronutz.com/en/learn/tcp-flow-and-congestion-control-in-one-sitting); [QUIC streams, loss and migration](https://ronutz.com/en/learn/quic-streams-loss-and-migration); [tunnel overhead, MTU and MSS](https://ronutz.com/en/learn/tunnel-overhead-mtu-and-mss) (the maximum transmission unit and maximum segment size); [the TCP proxy](https://ronutz.com/en/learn/tcp-proxy-layer-4); [retries, timeouts and idempotency](https://ronutz.com/en/learn/retries-timeouts-and-idempotency).
2. **Tunnels and virtual private networks (VPN).** [VPN fundamentals](https://ronutz.com/en/learn/vpn-fundamentals); [GRE tunnels](https://ronutz.com/en/learn/gre-tunnels-fundamentals), the Generic Routing Encapsulation (GRE) envelope; [IPsec and IKE](https://ronutz.com/en/learn/ipsec-and-ike-fundamentals), the Internet Key Exchange; [WireGuard, the small tunnel](https://ronutz.com/en/learn/wireguard-the-small-tunnel); [why the SSL-VPN is being dismantled](https://ronutz.com/en/learn/the-ssl-vpn-is-being-dismantled); and [Zscaler's tunnel types](https://ronutz.com/en/learn/zscaler-tunnel-types-z-tunnel-gre-ipsec) as the worked example.
3. **Proxies and the application delivery controller (ADC).** [HTTP proxies, forward and reverse](https://ronutz.com/en/learn/http-proxy-forward-and-reverse); [how a proxy auto-configuration (PAC) file chooses a proxy](https://ronutz.com/en/learn/how-a-pac-file-chooses-a-proxy); [load balancing: what actually decides where a request goes](https://ronutz.com/en/learn/load-balancing-what-actually-decides-where-a-request-goes); [health checks, persistence and the two questions every load balancer answers](https://ronutz.com/en/learn/health-checks-persistence-and-the-two-questions); [the history of load balancers and ADCs](https://ronutz.com/en/learn/adc-family-history); [GSLB in two tiers](https://ronutz.com/en/learn/gslb-two-tier-pool-then-member), the global server load balancing that picks a site; [inbound TLS at the reverse proxy](https://ronutz.com/en/learn/tls-reverse-proxy-inbound); and the HTTP set: [its five versions](https://ronutz.com/en/learn/http-versions-09-to-3), [its methods](https://ronutz.com/en/learn/http-methods-the-verbs), [its status codes](https://ronutz.com/en/learn/http-status-codes-the-five-families) and [its headers](https://ronutz.com/en/learn/http-headers-anatomy).
4. **Time, logs and management planes.** [Time, the dependency nobody lists](https://ronutz.com/en/learn/ntp-family-history); syslog field by field, from [the PRI number](https://ronutz.com/en/learn/syslog-pri-facility-severity) and [its facilities and severities](https://ronutz.com/en/learn/syslog-facilities-and-severities) through [the two message formats](https://ronutz.com/en/learn/syslog-message-formats), [syslog on network devices](https://ronutz.com/en/learn/syslog-on-network-devices) and [how syslog travels](https://ronutz.com/en/learn/syslog-transport) to [reading a message field by field](https://ronutz.com/en/learn/reading-a-syslog-message-field-by-field); [the history of observability](https://ronutz.com/en/learn/observability-family-history); [SNMP on network devices](https://ronutz.com/en/learn/snmp-on-network-devices) and [SNMP decoded](https://ronutz.com/en/learn/snmp-decoded-ber-pdus-oids-and-traps) (the Simple Network Management Protocol); [flow telemetry](https://ronutz.com/en/learn/flow-telemetry-netflow-sflow-and-ipfix); [accounting: who did what, to which device, and when](https://ronutz.com/en/learn/accounting-who-did-what-and-when); [what a network operating system actually is](https://ronutz.com/en/learn/network-operating-systems); and [out-of-band management and the console](https://ronutz.com/en/learn/out-of-band-management-and-the-console).
5. **Troubleshooting method.** [Map the path before you troubleshoot](https://ronutz.com/en/learn/map-the-path-before-you-troubleshoot); [capture points before packets](https://ronutz.com/en/learn/capture-points-before-packets); [the first hour of fault isolation](https://ronutz.com/en/learn/fault-isolation-first-hour); [baselines before you need them](https://ronutz.com/en/learn/baselines-before-you-need-them); [Wireshark and the capture stack](https://ronutz.com/en/learn/wireshark-and-the-capture-stack); [root cause is a verb, not a noun](https://ronutz.com/en/learn/root-cause-is-a-verb-not-a-noun); [blast-radius thinking before you change anything](https://ronutz.com/en/learn/blast-radius-thinking-before-you-change-anything); [cases for a vendor's technical assistance centre (TAC) that get triaged fast](https://ronutz.com/en/learn/tac-cases-that-get-triaged-fast); and [from the first symptom to a case that does not bounce](https://ronutz.com/en/learn/incident-to-escalation), the escalation that ends a long night.

## What to remember

- A port is a 16-bit number per transport; a socket is an address with a port; a connection is a pair of sockets; with the protocol added, the five-tuple names one conversation for every box in the path.
- System Ports 0 to 1023, User Ports 1024 to 49151, Dynamic Ports 49152 to 65535, never assigned (RFC 6335). The registry is a convention: a port number does not prove what is listening.
- Client ports are ephemeral and should be unpredictable and drawn from a wide range (RFC 6056); Linux uses 32768 to 60999 (28,232 ports), Windows 49152 to 65535 (16,384).
- To one server socket, one client address can hold no more connections than it has source ports, and TIME-WAIT (2 × MSL, 240 seconds with the specification's MSL) caps the rate at which they can be reused. Proxies and translators hit this first.
- Translation rewrites the five-tuple and must remember how; equal-cost routers and load balancers hash it so a flow stays on one path, and moving the hash boundaries moves flows.

<ReaderQuestions>
- Flows B and C in the first table differ only in the source port. What would a firewall rule written as "allow TCP to 203.0.113.80 port 443" have to know about either of them, and what would it never know?
- Using the arithmetic of the budget section, how many new connections a second could a proxy with four source addresses sustain towards one pool member on port 8080, if it closes first and its TIME-WAIT follows the specification?
- Why does RFC 6056 recommend the whole range 1024 to 65535 for ephemeral ports while IANA reserves only 49152 to 65535 as dynamic? What can go wrong when an ephemeral port lands on a registered number a local service needs?
- An equal-cost router hashes the five-tuple, and a QUIC client migrates to a new address. What happens to the hash, and to any middlebox that kept state for the old flow?
- Brazil chose to block outbound TCP port 25 in residential networks and to leave 587 alone. What does the choice rely on about who sends to port 25 and who submits on 587, and what would a spammer who stole a user's credentials still be able to do?
</ReaderQuestions>

## Sources

- [J. M. Winett, Lincoln Laboratory, RFC 147, The Definition of a Socket, 7 May 1971, RFC Editor text copy: the 1971 definition of a socket and of a port (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc147.html)
- [Information Sciences Institute, RFC 793, Transmission Control Protocol, September 1981, RFC Editor text copy: section 1.5, ports concatenated with addresses form a socket, a pair of sockets identifies a connection, one socket in many connections (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc793.html)
- [W. Eddy (ed.), RFC 9293, Transmission Control Protocol (TCP), Internet Standard 7, August 2022, RFC Editor text copy: section 3.1 (the port fields), 3.4.1 (a connection is a pair of sockets; TIME-WAIT limits reuse), 3.4.2 (MSL taken to be 2 minutes), 3.6.1 (TIME-WAIT for 2 × MSL), and the glossary definition of a socket (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc9293.html)
- [J. Postel, RFC 768, User Datagram Protocol, 28 August 1980, RFC Editor text copy: the port fields, the optional source port, protocol 17 (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc768.html)
- [M. Cotton, L. Eggert, J. Touch, M. Westerlund, S. Cheshire, RFC 6335, Service Name and Transport Protocol Port Number Registry Procedures, BCP 165, August 2011, RFC Editor text copy: sections 6, 7.2 and 9, the three ranges, the 76% and 9% figures, per-protocol assignment, the limits of port-based conclusions (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc6335.html)
- [IANA, Service Name and Transport Protocol Port Number Registry, last updated 19 November 2026, page and comma-separated copy: the registration procedures per range, the rows quoted, the counts of named assignments made for this article (accessed 23 November 2026)](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml)
- [IANA, Assigned Internet Protocol Numbers: protocol numbers 1, 6, 17, 33, 58 and 132 (accessed 23 November 2026)](https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml)
- [M. Larsen, F. Gont, RFC 6056, Recommendations for Transport-Protocol Port Randomization, BCP 156, January 2011, RFC Editor text copy: sections 1, 2.2 and 3.2, ephemeral ports, unique five-tuples, the whole range 1024-65535 (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc6056.html)
- [S. Amante, B. Carpenter, S. Jiang, J. Rajahalme, RFC 6437, IPv6 Flow Label Specification, November 2011, RFC Editor text copy: sections 1 and 3, the 5-tuple, its unavailable fields, the 2-tuple fallback (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc6437.html)
- [R. Krishnan et al., RFC 7424, Mechanisms for Optimizing Link Aggregation Group (LAG) and Equal-Cost Multipath (ECMP) Component Link Utilization in Networks, January 2015, RFC Editor text copy: appendix A, the 5-tuple and the share of large flows (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc7424.html)
- [C. Hopps, RFC 2992, Analysis of an Equal-Cost Multi-Path Algorithm, November 2000, RFC Editor text copy: hash-threshold, the four-region example, disruption of 3/10 (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc2992.html)
- [P. Srisuresh, K. Egevang, RFC 3022, Traditional IP Network Address Translator (Traditional NAT), January 2001, RFC Editor text copy: section 2.2, NAPT tuples (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc3022.html)
- [F. Audet, C. Jennings, RFC 4787, NAT Behavioral Requirements for Unicast UDP, BCP 127, January 2007, RFC Editor text copy: REQ-5, the two-minute minimum and five-minute recommended UDP mapping timer (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc4787.html)
- [B. Carpenter, S. Brim, RFC 3234, Middleboxes: Taxonomy and Issues, February 2002, RFC Editor text copy: section 1.1, the definition of a middlebox and the coinage credited to Lixia Zhang (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc3234.html)
- [J. Iyengar, M. Thomson (eds.), RFC 9000, QUIC: A UDP-Based Multiplexed and Secure Transport, May 2021, RFC Editor text copy: section 5.1, connection IDs (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc9000.html)
- [J. Arkko, M. Cotton, L. Vegoda, RFC 5737, IPv4 Address Blocks Reserved for Documentation, January 2010, RFC Editor text copy: the documentation blocks used in the examples (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc5737.html)
- [Linux kernel documentation, IP Sysctl: ip_local_port_range (default 32768 and 60999) and ip_unprivileged_port_start (default 1024) (accessed 23 November 2026)](https://docs.kernel.org/networking/ip-sysctl.html)
- [Linux man-pages, ss(8): options, state filters, dport and sport expressions, usage examples (accessed 23 November 2026)](https://man7.org/linux/man-pages/man8/ss.8.html)
- [Microsoft Learn, The default dynamic port range for TCP/IP has changed since Windows Vista and in Windows Server 2008: 49152 to 65535, formerly 1025 to 5000, the netsh commands (accessed 23 November 2026)](https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/default-dynamic-port-range-tcpip-chang)
- [Google Cloud, Backend services overview, session affinity: the default five-tuple hash (accessed 23 November 2026)](https://cloud.google.com/load-balancing/docs/backend-service)
- [R. Gellens, J. Klensin, RFC 6409, Message Submission for Mail, November 2011, RFC Editor text copy: submission as distinct from transport, port 587 (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc6409.html)
- [K. Moore, C. Newman, RFC 8314, Cleartext Considered Obsolete: Use of Transport Layer Security (TLS) for Email Submission and Access, January 2018, RFC Editor text copy: submission over implicit TLS on port 465 (accessed 23 November 2026)](https://www.rfc-editor.org/rfc/rfc8314.html)
- [Cristine Hoepers, CERT.br, NIC.br, CGI.br, Cartilha de Segurança para Internet e Gerência de Porta 25, presentation to the CGI.br meeting, Manaus, 11 September 2012, PDF: the study's figures, the timeline of the agreement, the submission diagram (accessed 23 November 2026)](https://www.cert.br/palestras/certbr-cgibr2012-09-11.pdf)
- [CGI.br, Resolução CGI.br/RES/2009/002/P, Recomendação para Adoção de Gerência de Porta 25 em Redes de Caráter Residencial, 24 April 2009, web page: the recommendation to e-mail and connectivity providers (accessed 23 November 2026)](https://www.cgi.br/resolucoes/documento/2009/002/)
- [CGI.br, NIC.br, Anatel and others, Acordo de Cooperação para Implementar a Recomendação da Gerência de Porta 25, São Paulo, 15 July 2011, PDF published by Antispam.br: items 2.1.1, 2.2 and 2.3 (accessed 23 November 2026)](https://www.antispam.br/porta25/brasil/acordo-cgibr-anatel-porta25.pdf)
- [Antispam.br (NIC.br), O que é Gerência de Porta 25, web page: the definition, the MAAWG recommendations, the note on port 465 (accessed 23 November 2026)](https://www.antispam.br/admin/porta25/definicao/)
- [Antispam.br (NIC.br), Recomendação da Gerência de Porta 25 no Brasil, web page: the documents of the Brazilian programme, the resolution's number 2009/02 (accessed 23 November 2026)](https://www.antispam.br/porta25/brasil/)
