Ports, Sockets and Multiplexing

Transport Layer · 25 min

Core CS · Computer Networks

IP finds the machine, the port finds the program

Every packet arriving for your laptop carries exactly one destination address, and that address names the machine and nothing else. Sixteen bits in the transport header close the gap to the process. Four numbers rather than two are what let one server port hold ten thousand conversations without mixing a single byte.

Step seven segments through one host and watch the four-tuple decide
One host at 10.0.0.5 is holding five sockets at once: nginx listening on port 80, two live connections to two different laptops, sshd on 22, and a DNS resolver on UDP 53. Every segment that arrives has to end up in exactly one of them. This lesson is the rule the host uses to pick.

01 The idea

The network layer stops at the front door

An IP packet carries exactly two addresses, and both of them name machines. Every router between here and there reads the destination address, looks it up in a table, and forwards; the previous module was entirely about how that lookup works. When the packet finally lands at 10.0.0.5, the network layer has finished its whole job, and what it has achieved has a name: host-to-host delivery. The right bits are on the right machine.

That is not what any application asked for. The machine at 10.0.0.5 is running a web server, an SSH daemon, a DNS resolver and a hundred other processes, and nothing in the IP header says which of them this packet belongs to. Closing the gap between the right machine and the right program on that machine is process-to-process delivery, and it is the first and most basic thing the transport layer does. Everything else transport can offer you is optional. This part is not, which is why even UDP, which declines almost everything, still has ports.

The mechanism is one number. The transport layer puts its own header in front of the application data, and the first four bytes of that header, in both TCP and UDP, are two 16 bit fields: the source port and the destination port. A TCP header is 20 bytes when no options are set and can reach 60 bytes with them. A UDP header is 8 bytes and never changes size. In both, the two ports come first, and that ordering is not decoration: they are the first thing the receiving host needs to read.

Sixteen bits gives 2¹⁶ = 65,536 distinct values, numbered 0 to 65535. Say 65,536 values, or say the range 0 to 65535, and both are right. Saying “65,535 ports” is the small slip that gets picked up, and you get that many per transport protocol rather than in total, which section 03 comes back to.

Now the pairing. An IP address on its own identifies a machine. A port on its own identifies nothing at all, because port 80 exists on every machine on the Internet. Put them together and you have an endpoint that is unique in the world, 10.0.0.5:80, and that pair is a socket. Here is the refinement the rest of the lesson turns on: a socket is enough to name an endpoint, but it is not enough to name a conversation. Two clients talking to that same 10.0.0.5:80 are two different conversations, and the host has to keep them apart with something. That something is the other end of each one.

IP delivers to a host; a port number is the 16 bit field that turns that into delivery to a process. A socket is one IP address plus one port. A TCP connection is named by four numbers, source IP, source port, destination IP and destination port, and that is the entire reason one server port can hold ten thousand conversations at once without confusing any of them.
MultiplexingThe sending side. Many processes hand data down to one transport layer; it wraps each chunk in a header carrying that process’s source port and the destination’s port, and passes all of them to a single IP layer. Many streams in, one stream of packets out.
DemultiplexingThe receiving side, and the harder half. One stream of packets comes up from IP. The transport layer reads the port numbers off each one, and for TCP the source address and port as well, and drops the payload into the buffer of exactly one socket. One stream in, many processes out.
SocketAn endpoint: one IP address plus one port, written 10.0.0.5:80. Your program holds it as a file descriptor it reads and writes; on the wire it is only those two numbers, and the operating system keeps the table that maps between the two views.

02 Worked example

One click, from the source port to the right socket

This is the scene for the whole lesson. A laptop at 203.0.113.7 opens a page on a web server at 10.0.0.5. That server is also running sshd and a DNS resolver, so it holds five sockets in all, and it is the same host the console in section 04 runs. Read the five nodes left to right. The highlighted one is where the decision actually happens; the other four are setting it up.

The client picks a source portThe destination port is fixed at 80 by the URL. Nobody told the laptop what its own port should be, so its kernel takes a free number from the ephemeral range and returns 52310. The connection is now fully named: (203.0.113.7, 52310, 10.0.0.5, 80).
Multiplex on the way outTCP writes 52310 into the source port field and 80 into the destination port field, the first four bytes of a 20 byte header. IP wraps that with source 203.0.113.7 and destination 10.0.0.5. Twenty other processes are doing the same, and it all leaves as one stream.
IP stops at the machineEvery router on the path reads 10.0.0.5 and nothing else. The ports sit in the transport header, which a router never has to open. When the packet lands, the network layer is finished and the question of which process wants it has not been touched.
Demultiplex on all fourThree of the five sockets are on port 80: one listening, one established for this laptop and one established for a different client. The destination port narrows five to three and then stops helping. Compare all four numbers and exactly one established socket agrees on every one. Payload delivered there.
A second tab, nothing mixesThe same laptop opens the page again in a new tab. Same source IP, same destination IP, same destination port 80. Only the source port changes, to 52311, and it is enough: a fourth socket on port 80 appears, pinned to that four-tuple, and the two tabs never see each other’s bytes.

Count what changed between the fourth node and the fifth. Three of the four numbers were identical and one differed, and that one number is the whole difference between two mixed-up tabs and two clean conversations. State the argument in that form and it is hard to forget: the destination pair says which door, the source pair says which visitor, and a server needs both to answer the right person. A demultiplexer keyed on the destination pair alone would have dropped both tabs into one buffer, and the reply to the second request could be painted into the first tab.

The reply direction is worth a sentence, because it is the same mechanism with the fields swapped. When the server answers, its source becomes (10.0.0.5, 80) and its destination becomes (203.0.113.7, 52310). The laptop then runs the identical four-field lookup on the way in. Nothing about this is asymmetric, which is why the proper name for the four numbers is a socket pair: one socket at each end, and the connection is the pair.

One caution about the first node, because it is exactly the sort of detail an interviewer follows up on. IANA calls 49152 to 65535 the dynamic or private range, and that is the answer to give when asked where a source port comes from. Linux does not use it: the default value of net.ipv4.ip_local_port_range is 32768 60999, which dips well into the registered range. Windows has used the IANA range since Vista. Give the standard, then name the difference in one clause, and the follow-up question stops there.

03 Mechanics

The ranges, the ports, and the two demultiplexers

Four tables, in the order the questions arrive. First the three ranges. The boundaries are exact numbers and they get asked for as exact numbers, so the count column is there to be checked: the three add up to 65,536 or one of your boundaries is wrong.

RangeNumbersHow manyWho assigns themWhere you meet it
Well-known (system)0 to 10231,024IANA, through a standards processThe server side of every protocol in the next table. Binding one on Linux or macOS needs root, or the CAP_NET_BIND_SERVICE capability.
Registered (user)1024 to 4915148,128IANA on request, but no privilege is needed to bind oneMySQL 3306, PostgreSQL 5432, Redis 6379, Tomcat 8080. Everything you run in a lab lives here.
Dynamic (private, ephemeral)49152 to 6553516,384Nobody. The kernel picks a free one per outgoing connectionYour own source port, every time you open a connection. You never choose it and you rarely look at it.
The three must total the field width. 1,024 + 48,128 + 16,384 = 65,536, which is 2¹⁶. Count a range inclusively at both ends: 49151 − 1024 + 1 = 48,128. Dropping the + 1 is where the off-by-one comes from.

What the privilege on the first range is actually protecting. A well-known port carries an implied promise about what is listening there: connect to port 25 of a mail server and you expect SMTP. If any user on a shared machine could bind port 25, any user could impersonate that promise. So Unix systems refuse the bind below 1024 unless the process is root or holds CAP_NET_BIND_SERVICE. In production the three usual answers are to grant that one capability instead of running as root, to let systemd open the socket and pass the descriptor to an unprivileged process, or to listen on 8080 and put a reverse proxy in front.

Now the list. These are the ports a placement interview actually asks for, and the transport column is asked for as often as the number.

PortServiceTransportWhat to say about it
20FTP dataTCPCarries the file itself. In active mode the server opens this connection back towards the client.
21FTP controlTCPCommands and replies. Two ports for one protocol is why FTP gets asked about at all.
22SSHTCPAlso carries scp and sftp, so one port covers three tools.
23TelnetTCPThe same job as SSH with nothing encrypted. Name it as the thing SSH replaced.
25SMTPTCPRelay between mail servers.
53DNSUDP and TCPUDP for ordinary queries, TCP when the response will not fit or for a zone transfer. The only row here with two transports.
67DHCP serverUDPThe server listens here.
68DHCP clientUDPThe client listens here. Both ends are fixed because the client has no address yet and must broadcast.
80HTTPTCPThe default when a URL has no port.
110POP3TCPDownloads mail and by default removes it from the server.
143IMAPTCPLeaves mail on the server, which is why every phone uses it.
443HTTPSTCPAnd UDP 443 for HTTP/3 over QUIC, which is the modern follow-up question.
587SMTP submissionTCPClient to server, authenticated. 25 is relay, 587 is submission, and swapping them is the trap.

Two rows worth one extra sentence each. DNS uses UDP because a query and its answer are one small exchange, and paying a handshake round trip to look up an address would double the cost of every page load. The classic limit is 512 bytes of DNS payload in a datagram; if the answer is larger, the server sets the truncated bit and the resolver asks again over TCP 53, and the EDNS0 extension raises that limit to negotiate larger datagrams instead. DHCP is stranger: the client has no IP address at the moment it asks for one, so it sends from 0.0.0.0:68 to the broadcast address 255.255.255.255:67. Both ports must be fixed and well-known because neither end can be told the other’s ephemeral port in advance.

This is the table the lesson is really about. Same job on both sides, and a genuinely different amount of work.

DemultiplexingUDPTCP
A socket is keyed ondest IP, dest port — 2 fieldssrc IP, src port, dest IP, dest port — 4 fields
The source fields areread, but not used to choose the socket. Handed to the application beside the payloadpart of the key, and compared on every arriving segment
Two clients to the same server portone socket, both datagrams land in ittwo sockets, one per client
Sockets the server holdsone, for as long as the process runsone listening socket plus one per live connection
API shapesocket, bind, then recvfrom in a loopsocket, bind, listen, then accept, which returns a new socket each time
Nothing bound on that portICMP type 3 code 3, port unreachableTCP RST segment
Header cost8 bytes, fixed20 bytes minimum, 60 with options
Selected byIPv4 protocol field 17IPv4 protocol field 6

Listening sockets, and the 0.0.0.0 you keep seeing. A listening socket never carries data. It sits at a local address and port with a wildcard peer, written *:*, and its only job is to catch a SYN for a connection that does not exist yet; accept then hands you a brand new socket pinned to that one four-tuple, and every byte flows through the new one. The local half of a socket is an address and a port, not a port alone, and that has a consequence people meet the hard way. A server that binds 10.0.0.5:8080 has claimed that port on one interface only, so a second process can bind 192.168.1.9:8080 on another interface and both succeed. Bind 0.0.0.0:8080 instead and you are asking for that port on every interface at once, which is what most servers do by default and what ss prints as 0.0.0.0:8080 or *:8080.

Two separate port spaces, not one. TCP and UDP each get their own 65,536 numbers, because the IPv4 protocol field is consulted before the port table is. A process can hold TCP 53 while a completely different process holds UDP 53, and neither bind fails. That is not a corner case; it is exactly how a DNS server is normally deployed, and it is why “is port 53 free” is not a well-formed question until you say which protocol.

Last, what the transport layer is actually offering. Read this column by column rather than row by row: TCP is a bundle, and UDP is what is left when you decline the bundle.

ServiceTCPUDPIf you pick UDP, who does it
Process-to-process deliveryyesyesNeither can decline this. It is what a port is for.
Error detection over the payloadyes, checksum mandatorychecksum optional in IPv4, mandatory in IPv6The application, or nobody.
Reliable deliveryyes, acknowledgements and retransmissionnoThe application. A DNS resolver asks again after a timeout.
In-order deliveryyes, sequence numbers reorder the streamnoThe application. RTP carries its own sequence number for this.
Flow controlyes, the receive windownoNobody. A fast sender can drown a slow receiver.
Congestion controlyesnoThe application. QUIC implements it in user space over UDP.
Connection setup costa three-way handshake, one round trip before any datanone, the first datagram carries data

A menu, not a mandate. The rows above are services the transport layer offers, and the interesting thing about UDP is not that it lacks them but that declining them is a design decision somebody made on purpose. Live audio does not want retransmission, because a frame that arrives 200 milliseconds late is useless however perfectly it arrives, and worse, TCP would hold every later frame behind it while it recovered the lost one. A DNS query does not want a handshake, because the handshake would cost more than the query. So the honest summary of the whole layer is this: process-to-process delivery is compulsory, everything else is a menu, and UDP is the order that takes the first item and nothing else.

05 Cheat sheet

The numbers to have ready

Every row is something you can be asked to state in under ten seconds. The right-hand column is the specific wrong answer that gets given, not a general caution.

What they askThe answerThe trap
Width of the port field16 bits, 65,536 values, 0 to 65535saying 65,535 ports — and forgetting it is per protocol
Well-known range0 to 1023, which is 1,024 numbersSaying 1 to 1024. Binding one on Unix needs root or CAP_NET_BIND_SERVICE.
Registered range1024 to 49151, which is 48,128 numbersClaiming it runs to 65535, which erases the third range entirely.
Dynamic or ephemeral range49152 to 65535, which is 16,384 numbersquoting IANA as what Linux does — its default is 32768 to 60999
What a socket isone IP address plus one port, 10.0.0.5:80calling the four-tuple a socket — that is a socket pair, which is a connection
What names a TCP connectionsrc IP, src port, dest IP, dest portGiving two fields, which merges every client on one server port into one stream.
What UDP demultiplexes ondestination IP and destination portclaiming UDP uses the four-tuple too — it has no connections to separate
TCP segment to a closed porta RST segmentSaying ICMP. A firewall dropping it silently is a third outcome and not the protocol’s.
UDP datagram to a closed portICMP type 3 code 3, port unreachableSaying RST. UDP has no connections, so it has no reset.
Header sizesTCP 20 bytes min, 60 with options; UDP 8 fixedQuoting the TCP header as a flat 20. It is a minimum.
TCP 80 and UDP 80two different sockets, two separate port spacesone shared table of 65,536 ports per machine
The ports to memorise20 21 22 23 25 53 67 68 80 110 143 443 58725 versus 587 — 25 is relay between servers, 587 is authenticated submission
The two numbers live in two headersThe port is in the transport header and the address is in the IP header, so naming a socket takes fields from two layers. That is why a router can forward without ever opening a transport header, and why a firewall or a NAT box is reaching above its own layer the moment it looks at a port.
One listening socket, many connection socketsThe listener sits at a local address and port with a wildcard peer and never carries data. accept returns a new socket pinned to one four-tuple, and that is the socket the bytes flow through. A server holding ten thousand connections holds ten thousand and one sockets on one port.
The limit is on the client, not the serverA server’s port is one number and it never runs out of them. What runs out is the pool of source ports a single client, or a NAT box standing in for many clients, can put in front of it, and that is where the real ceiling on simultaneous connections sits.

06 Where & why

Where these numbers show up on a real machine

None of this is a teaching abstraction. Each of these four is a socket table with a local pair, a remote pair, a rule for choosing a row, and a fixed answer when no row matches. Two of them differ from the textbook in a way worth naming out loud.

Linux · ss
The four-tuple printed one row at a time

ss -tan prints one line per TCP socket with the local address and the peer address side by side, which is the four-tuple with the fields in that order. A LISTEN row shows a peer of *:*, meaning any remote endpoint; an ESTAB row shows a real one. Run it with a browser open and you will see several rows sharing one server address and differing only in the client port. The ephemeral ports it draws from are set by net.ipv4.ip_local_port_range, whose default is 32768 60999 and not the IANA 49152 to 65535.

OpenSSH
Why the config file has a Port line at all

sshd binds TCP 22, which is inside the privileged range, so it starts as root and drops privileges afterwards. Changing Port 22 to Port 2222 in sshd_config moves it into the registered range where an unprivileged user can bind it, and every client then has to be told with ssh -p 2222, because nothing in the protocol advertises the move. That trade, one privileged default against one extra argument forever, is the well-known range doing exactly its job.

nginx
One listening socket, tens of thousands of connection sockets

A worker holds one listening socket on port 443 and one further socket per live connection, all sharing that same local pair and differing only in the remote half. worker_connections caps how many it will keep, and the operating system open-file limit caps it again, because every socket is a file descriptor. When several workers need to accept in parallel they use SO_REUSEPORT to each hold their own listening socket on the same port, and the kernel spreads arriving connections across them by hashing the four-tuple.

Google Public DNS 8.8.8.8
One UDP socket, the whole world

A resolver at 8.8.8.8:53 is reached over UDP by clients that have no connection to it and never had one. Every query lands in the same socket, and the server learns who sent it from the sender address delivered beside the payload, which it then uses as the destination of the reply. The same address answers on TCP 53 when a response will not fit in one datagram, and on TCP 443 for DNS over HTTPS, which exists largely to get through networks that filter port 53.

When you meet a networking problem in a job, the first genuinely useful thing you can do is print the socket table and ask which row the traffic should have hit. Almost every “the service is not responding” ticket resolves to one of three answers: nothing is bound to that port, something is bound but only on one address, or it is bound on the other transport protocol.

07 Interview questions

What they ask, and what they follow up with

This topic is asked early in an interview because it is cheap to check and expensive to fake. The pattern is that a definition question is followed immediately by a number question, so give the boundary values without being asked for them; that one habit does more for you here than any amount of extra theory.

What does the transport layer give you that the network layer cannot?
Process-to-process delivery. IP gives you host-to-host delivery: every router on the path reads the destination IP address and nothing else, so when the packet lands the right bits are on the right machine and nobody knows which of its hundred processes wants them. The transport layer adds a header whose first two fields are a source port and a destination port, and those 16 bit numbers name the program. Everything else transport offers is optional, which is why even UDP, which declines almost all of it, still carries ports.
What exactly is a port number, and how many are there?
It is a 16 bit field in the transport header, so there are 2¹⁶ = 65,536 of them, numbered 0 through 65535. It sits in the transport header and not the IP header, which is why a router never has to open it and why a firewall filtering on ports is doing strictly more work than a router does. Say 65,536 values or say the range 0 to 65535; answering “65,535 ports” is the small slip that gets noticed.
Give me the three port ranges with their boundaries.
Well-known or system ports are 0 to 1023, which is 1,024 numbers, assigned by IANA and privileged to bind on Unix. Registered or user ports are 1024 to 49151, which is 48,128 numbers, handed out by IANA on request but bindable by anyone. Dynamic, private or ephemeral ports are 49152 to 65535, which is 16,384 numbers that nobody assigns because the kernel picks one per outgoing connection. They add to 65,536, and that sum is the check. One caveat worth volunteering unprompted: Linux does not use the IANA ephemeral range by default, it uses 32768 to 60999.
What is a socket, and is a socket the same thing as a connection?
A socket is an endpoint: one IP address and one port, written 10.0.0.5:80. A connection is not one socket, it is a pair of them, and TCP names it by all four numbers, source IP, source port, destination IP and destination port. That distinction is the point of the whole topic: a server holds one listening socket at 10.0.0.5:80 and one further socket per live connection, all sharing that local pair and differing only in the remote half. There is a third meaning too, since in the Berkeley API you hold a socket as a file descriptor, and separating the three out loud is worth doing.
Two browser tabs are open on the same website. Why do the responses not get mixed up?
Because the two connections have different four-tuples. Both tabs share a source IP, a destination IP and destination port 80, but the client kernel picks a fresh ephemeral source port for the second one, so the keys differ in exactly one field. The server holds two separate connection sockets and demultiplexes every arriving segment on all four fields, and the client does the same on the replies. If either side keyed only on the destination pair, both tabs would land in one buffer and the answer to one request could be painted into the other tab.
How is UDP demultiplexing different from TCP demultiplexing?
UDP keys a socket on the destination IP and destination port only, so two datagrams from two different clients addressed to the same server port land in the same socket, and the application separates them using the sender address that recvfrom hands it beside the payload. TCP keys on all four fields, so those same two datagrams as segments would go to two different sockets. The reason for the difference is that UDP has no connections to keep apart: a UDP server usually holds exactly one socket for its whole life, while a TCP server holds one listening socket plus one per live connection.
A segment arrives for a port with nothing bound. What happens?
For TCP the host replies with a RST segment, and that is what surfaces in an application as connection refused. For UDP there is no RST, because a reset is a connection idea and UDP has no connections, so the host sends back an ICMP Destination Unreachable message, type 3 with code 3, port unreachable. Both tell the sender immediately. In practice a firewall often drops the segment silently instead, which is why a blocked port hangs and a closed port fails fast, and that difference is exactly what a port scanner is reading.
Why does binding to port 80 need root?
Because 0 to 1023 are privileged on Unix systems: the kernel refuses the bind unless the process is root or holds CAP_NET_BIND_SERVICE. The reasoning still holds, that a well-known port carries an implied promise about what is listening there, so an ordinary user should not be able to put a fake SMTP server on port 25 of a shared machine. The usual production answers are to grant only that capability rather than run as root, to let systemd open the socket and pass the descriptor to an unprivileged process, or to listen on 8080 and put a reverse proxy in front.
Where in the packet are the port numbers, and why does the answer matter?
The ports are in the transport header and the IP addresses are in the IP header above it, so identifying a socket takes fields from two different layers. That is why a router can forward a packet without ever parsing a transport header, and why any device that does look at ports, a firewall or a NAT box, is reaching above its own layer to do it. It also explains a detail people find odd: the TCP and UDP checksums cover a pseudo-header containing the IP addresses and the protocol number, because the transport layer needs to be sure the segment reached the right port on the right host and not the right port on the wrong one.
Define multiplexing and demultiplexing in one sentence each.
Multiplexing is the sending side: the transport layer collects data from many sockets, stamps each chunk with its own source and destination ports, and hands all of it to one IP layer, so many streams become one stream of packets. Demultiplexing is the receiving side: one stream comes up from IP and the transport layer reads the ports, and for TCP the source address and port as well, to drop each payload into exactly one socket buffer. Many-to-one going out, one-to-many coming in, and demultiplexing is the harder half because it is where a decision has to be made.
TCP gives you strictly more than UDP. So when would you actually choose UDP?
When what TCP adds costs more than it is worth. Retransmission and in-order delivery mean a single lost packet stalls everything queued behind it, which is the wrong trade for live audio or video, where a frame that arrives 200 milliseconds late is useless however perfectly it arrives. The handshake costs a round trip before any data moves, which is why DNS asks over UDP and only falls back to TCP for large responses. The honest framing is that the transport layer is a menu rather than a mandate: reliability, ordering, flow control and congestion control are all on offer, and picking UDP is deciding to decline them and implement only the ones you actually need, which is exactly what QUIC does on top of UDP 443.

08 Practice problems

Six to work on paper

Write every four-tuple out as four separate numbers before you decide anything, even where the answer looks obvious. Two of these six turn on the fact that a socket has a local half with two parts in it, and one of them cannot be answered at all until you notice which field a middlebox is allowed to change.

Which socket gets it

Easy
A host at 10.0.0.5 holds three TCP sockets: a listening socket on 10.0.0.5:443 with peer *:*, and two established ones with peers 198.51.100.4:51000 and 198.51.100.4:51001. Four segments arrive in this order, all addressed to 10.0.0.5:443: data from 198.51.100.4:51001, data from 198.51.100.4:51000, a SYN from 203.0.113.9:51000, then data from 203.0.113.9:51000. Name the socket each one is delivered to and the field that settled it.
Follow-up
Two of the four segments carry the same source port and two carry the same source IP, so no single field settles all four. One of them is delivered to a socket that did not exist when the sequence started, and the segment after it must not go back to the listener.
Show the hint
Compare all four fields against every socket before you decide, and note what changes in the socket table the moment a SYN is accepted.

What the header costs

Easy
One process sends 100 bytes of application data over UDP and another sends the same 100 bytes over TCP with no options set. For each, give the size of the transport segment, the size of the IPv4 packet assuming a 20 byte IP header, and the percentage of that packet which is application data.
Follow-up
Both answers use header sizes stated in this lesson and neither needs anything from outside it, but one of the two transport header sizes is a minimum rather than a fixed value. Saying which one, and what would change it, is half of what is being tested.
Show the hint
Add the headers rather than estimating them, and take the percentage against the full packet size and not against the transport segment.

Which field did the work

Medium
Four TCP segments arrive at 10.0.0.5. A is (203.0.113.7, 51000, 10.0.0.5, 80), B is (203.0.113.7, 51001, 10.0.0.5, 80), C is (198.51.100.4, 51000, 10.0.0.5, 80) and D is (203.0.113.7, 51000, 10.0.0.5, 443). For each of the six pairs, say whether a demultiplexer keyed only on the destination port separates them, whether one keyed on all four fields does, and which field carried the decision.
Follow-up
The destination port already separates three of the six pairs on its own, so those three prove nothing about why four fields exist. Of the remaining three, exactly one differs in two fields at once, and you have to say which single field would have been enough by itself.
Show the hint
Lay the four segments out as four rows of four numbers and compare two rows at a time, reading left to right until a column differs.

Same port, four binds

Medium
A machine has three local addresses: 10.0.0.5, 192.168.1.9 and the loopback 127.0.0.1. Four processes ask to bind TCP port 9000, in this order: P1 to 10.0.0.5:9000, P2 to 192.168.1.9:9000, P3 to 0.0.0.0:9000, P4 to 127.0.0.1:9000. Say which of the four binds succeed and which fail, naming what each failure collides with, then say which single change to the order would leave exactly one bind succeeding.
Follow-up
The port is 9000 in all four requests, so the port cannot be what decides any of them. The order the requests arrive in changes the answer completely, and the one request that fails here is the one most servers issue by default.
Show the hint
The local half of a socket has two parts, not one. Write both parts out for every request, then ask of each new request whether the set of addresses it claims overlaps a set already claimed.

How many can it hold

Medium
A server socket is fixed at 10.0.0.5:443. Give the number of distinct TCP connections that socket could name if every IPv4 address and every port number were available to clients, then give the number a single client machine could open to it under the Linux default ephemeral range of 32768 to 60999. State which of the two is the number that bites in practice, and whose resource it is.
Follow-up
The two figures differ by around ten orders of magnitude, and the small one is not a property of the server at all. The number 65,535 appears in neither answer, which is the whole point of asking.
Show the hint
Two of the four fields are pinned by the server socket, so count what the other two can take between them; for the second figure only one field is free, and count inclusively at both ends.

One address, two laptops

Hard
Two laptops behind one home router, 192.168.1.10 and 192.168.1.11, each open a connection to 203.0.113.10:443, and both kernels happen to pick source port 52000. The router has a single public address, 198.51.100.9. Give the four-tuple of each connection as the laptops see it, the four-tuple the server sees, and the translation table the router must hold so that replies reach the right laptop.
Follow-up
The server has to see two connections that differ from each other, and the only field the router is free to change is one it does not own. Work out what the server would do if the router changed nothing, and you have the reason a box that calls itself a router has to read a transport header at all.
Show the hint
Write the four numbers of each connection as a column, once before the router and once after it, and find the entry that would otherwise be identical in both rows.