EMZETT.
Login

Source Port

In short: The port from which a network connection originates — usually assigned at random by the operating system from the upper port range.

In more detail: For every outgoing connection (e.g. a browser calls up a website), a free, random source port is reserved locally, through which the reply later finds its way back. Together with the destination port and the IP addresses, it forms the so-called socket pair that uniquely identifies a connection.

In Depth

When a browser calls up a website, the target server knows where to send its reply because, with every new outgoing connection, the client’s operating system automatically assigns a free source port from the dynamic range (usually 49152–65535) — this port stays reserved for the duration of the connection and is released again once it ends. The destination port, on the other hand, usually stays fixed (e.g. 443 for HTTPS), since the server has to be reachable under this known port.

This combination of local source port and remote IP address + destination port allows a single device to maintain several independent connections to the SAME target server at the same time (e.g. several parallel downloads from the same website) — each gets its own source port and is therefore uniquely distinguishable for the operating system, even though the destination IP and destination port are identical.

Why the range is limited

The dynamic port range (49152–65535, as recommended by IANA) offers only around 16,000 ports — with very many simultaneous connections (e.g. a heavily loaded server that itself establishes connections to many backend services as a client), this supply can theoretically be exhausted, especially if connections aren’t released immediately after they end but only after a waiting period (the TIME_WAIT state in TCP). In practice this is avoided by distributing load (load balancing) across several servers or by reusing existing connections (connection pooling).

NAT and port translation

Behind a router with network address translation (NAT), the locally assigned source port is additionally translated once more: several devices in the same home network share a single public IP address, so the router keeps an internal table of which local source port belongs to which internal device, and assigns its own public source port for the connection visible to the outside. Reply packets from outside thus arrive at the router and are routed correctly back to the internal device that originally made the request, based on this table.

See also: Destination port, Port, Sockets