What is the actual max packet size for a TCP connection?

Why you should avoid packet fragmentation

ยท

2 min read

By default, the max limit of a TCP packet is 64K or 65535 bytes.

1GB if you use window scaling (by left shifting the window size by 14).

Unfortunately, we cannot use such large MTUs.

The MTU of the lowest layer, i.e., the Network Layer matters. Data travels from the highest to the lowest layer during transmission. Thus, having a higher MTU in the upper layers does not matter.

If the lower layer has a smaller MTU, it will break your TCP packet down into smaller fragments before transmission.

The MTU of a classic Ethernet Layer is 1500 bytes.

Your TCP packet will go through fragmentation if the size exceeds 1500 bytes.

Checking further, you would find there are TCP and IP headers that occupy 40 bytes (20 + 20) with no options. Best-case scenario? They occupy 40 bytes. Worst case, 84 (60 + 24) bytes.

This gives the max TCP packet size to be 1460 bytes. With no fragmentation.

Why you should avoid packet fragmentation

If an application is sending big chunks of packets way above the connection's MTU (MTU can vary from connection to connection) and relying on the router to do the fragmentation during transmission, there might be some drawbacks:

  1. Reliability highly depends on the delivery of all fragments. A packet is essentially lost and needs to be retransmitted even if only 1 packet was undelivered out of 4.
  2. Diving a 5000 bytes packet into 4 packets of sizes 1500, 1500, 1500, and 500 is a waste of resources as the last fragment won't fully use the packet space. This leads to noisy packets.
  3. The receiving end of the connection must hold the fragments in the receiving buffer until all fragments corresponding to a single packet arrive. This opens doors to malicious attempts at memory exhaustion.

TCP packet fragmentation

Further Readings

  1. Path MTU discovery
  2. Stackoverflow thread
ย