How to calculate Maximum Segment Size in TCP?
Maximum Segment Size refers to size of the largest segment that local host accepts within a single packet. It denotes largest amount of data that host can accept in single TCP segment.
For establishing the TCP connection, both sender and receiver indicates Maximum Segment Size they can accept. While transmitting the packets over TCP connection sender reduce the size of packet according to MSS received. It is useful for devices with small amounts of memory, because it allows the device to set a limit on the size of the packets it will receive.
Network Driver knows Maximum Transmission Unit of directly attached network. Maximum Transmission Unit is largest size frame that can be transmitted across data link layer. IP asks the value of Maximum Transmission Unit from Network Driver and use it in the following relation to calculate Maximum Datagram Data Size :
MDDS = MTU - IP_HL where, MDDS = Maximum Datagram Size MTU = Maximum Transmission Unit IP_HL = IP Header Length
Maximum Datagram Data Size refers to largest amount of data that is accepted in IP packet.
Now, TCP asks the value of Maximum Datagram Data Size from IP and use it in the following relation to calculate Maximum Segment Size :
MSS = MDDS - TCP_HL where, MSS = Maximum Segment Size MDDS = Maximum Datagram Data Size TCP_HL = TCP Header Length
Example : Suppose Maximum Transmission Unit have payload of 1500B, header which contain information about the amount of packets and tail denoting the end of packet flow in data link layer and size of both TCP and IP header is 20B each. So, we can find the Maximum Segment Size by following the given steps :
- Payload of 1500B is received by network layer which is divided as 1480B Maximum Datagram Data Size load and 20B IP header. It means IP packet transmitted through network layer can have information stored up to 1480B and have 20B header to store information like IP version, source address, destination address and time-to-live about the packet.
- Payload of 1480B is received by transport layer which is divided as 1460B Maximum Segment Size and 20B TCP header. It means TCP packet transmitted through transport layer can have information stored up to 1460B and have 20B header to store information like source port, destination port, sequence number, acknowledgement number, header length, checksum, window size, urgent pointer and reserved bits.
Hence, Maximum Segment Size will be 1460B i.e. 1460B data can be received in a single TCP packet.
Maximum Segment Size must be chosen by considering following performance issues :
- Overhead Management : If MSS is too low then it will lead to inefficient use of bandwidth as amount of data stored in the segment would be comparative to headers which is not efficient.
- IP Fragmentation : If MSS is too large then it will lead to large IP datagrams which would require fragmentation before they can be transmitted. Fragmentation will reduce efficiency and increase the chances of part of a TCP segment being lost, resulting in the entire segment needing to be retransmitted.