MSS (Maximum Segment Size) works by measuring the size of the data payload within a TCP packet, excluding the IP and TCP headers. In essence, it determines the largest amount of data that can be transmitted in a single segment to avoid IP fragmentation at the sender's side.
Here's a breakdown:
-
What MSS Measures: MSS specifically measures the data payload of a TCP segment. This is the actual information being transmitted (e.g., website content, file data).
-
Exclusion of Headers: MSS does not include the size of the IP or TCP headers. These headers contain control information needed for routing and reliable delivery, but they are overhead, not user data.
-
Purpose: Avoid Fragmentation: The primary goal of MSS is to avoid IP fragmentation. Fragmentation occurs when a packet is too large to be transmitted over a network link with a smaller Maximum Transmission Unit (MTU). Fragmenting packets adds complexity and overhead to the networking process, potentially leading to performance issues.
-
Analogy: As mentioned, think of a transport truck. The header is the truck cab and trailer hitch. The payload is the trailer and cargo inside. MSS is the scale that only measures the weight of the trailer and its cargo, not the truck cab itself.
-
MSS Negotiation: During the TCP handshake (the initial connection setup), the sending and receiving devices exchange their MSS values. Each side indicates the maximum segment size it is willing to receive. The lower of the two MSS values is then used for the connection. This ensures that both sides can handle the packet sizes being transmitted.
-
How it Works in Practice: Let's say a client's network adapter has an MTU of 1500 bytes. The IP header is typically 20 bytes, and the TCP header is typically 20 bytes. The client would advertise an MSS of 1460 bytes (1500 - 20 - 20). The server might advertise a different MSS. The smaller of the two advertised MSS values will be used. If the server advertises 1400 and the client 1460, the actual MSS in use will be 1400 bytes.
In summary, MSS is a crucial mechanism in TCP that helps optimize network performance by determining the largest data payload size for a segment, thereby minimizing the risk of IP fragmentation.