12

From many tutorials, I get follow knowledge(maybe I'm misunderstood) :

  • maximum of an Ethernet packet is about 1500 bytes.

  • maximum of an IP packet is about 65535 bytes.

  • maximum of a UDP packet is 65515 bytes

But when I made a test and watch Wireshark, I get a different answer.

  1. I try to send some big data with TCP protocol.

    Socket con = new Socket("localhost", 8088);
    OutputStream os = con.getOutputStream();

    StringBuilder s = new StringBuilder();
    for( int i = 0; i < 10000; i++) {
      s.append("Hello world");
    }
    // about 110k bytes
    byte[] data = s.toString().getBytes();

    os.write(data);
    os.close();
    con.close();

This is my Java code (it's not necessary to understand this.), I try to send 110k bytes data with a TCP connection. This is my Wireshark.

enter image description here

My 110k bytes message is split to 7 packets, I think this shows that maximum length of a TCP packet is 16388 bytes.

  1. Then, I try to send a UDP packet:
    DatagramSocket client = new DatagramSocket(50555);

    StringBuilder s = new StringBuilder();
    for( int i = 0; i < 10000; i++) {
      s.append("Hello world");
    }
    // 110k bytes
    byte[] data = s.toString().getBytes();

    int messageLength = data.length;
    for (; ; messageLength--){
      try{
        DatagramPacket packet = new DatagramPacket(data, messageLength, 
          new InetSocketAddress("localhost", 8088));
        // If packet is still too lang, above line will throws an exception

        // If there is not any exception, means we can send this packet
        // and this messageLength is the limit value for a UDP packet.
        client.send(packet);
        System.out.println("message length is " + messageLength);

        // break for loop
        break;
      } catch(Exception e){
        // fail to send and continue for loop
      }
    }
    client.close();

the result ismessage length is 65507.

I was really confused:

  • IP protocol build on Ethernet or something, Why an IP packet can be 65535 bytes when Ethernet can only send 1500 bytes?

  • Why an TCP packet is only 16388 bytes?

Then I have read many post on SOF or other websites, But I don't get an answer, I think is not duplicate to others.

8
  • 4
    "Why an IP packet can be 65535 bytes when Ethernet can only send 1500 bytes?" Ethernet is not the only data-link protocol that can carry IP. More devices are now shipped with Wi-Fi than with ethernet. There are other protocols each of which has a different MTU (payload, e.g. IP, size).
    – Ron Maupin
    Feb 26, 2019 at 4:03
  • 6
    Terminology please. Maximum length of an Ethernet frame is 1500 bytes. IP packets can span frames in the physical layer. Maximum length of a UDP datagram is 65507 bytes, given by the IP maximum packet size (which is 65535, and not 'about'), less 20 for the IP header, less 8 for the UDP header. The maximum length of a TCP segment is described in 32 bits.
    – user207421
    Feb 26, 2019 at 7:44
  • 3
    @user207421 The maximum length of an Ethernet frame (w/o options) is 1518 bytes. 1500 bytes is the maximum L2 payload size or SDU (aka MTU for IP).
    – Zac67
    Feb 26, 2019 at 8:17
  • 1
    @scai IEEE-802 spec says 1500 bytes. Anything else is a "non-standard hack". (they refuse to add jumbo frames to the spec for backwards compatibility)
    – Ricky
    Feb 26, 2019 at 15:24
  • 1
    What do you mean by "is not suit"?
    – Barmar
    Feb 26, 2019 at 18:47

2 Answers 2

14

IP protocol build on Ethernet or something, Why an IP packet can be 65535 bytes when Ethernet can only send 1500 bytes?

Ethernet is one of several physical layers which can be used to to transport IP (and also protocols besides IP). The size of the packet a physical layer can transport is specific to this physical layer, other physical layers have other properties. Note that in your specific case of communicating on localhost (127.0.0.1) no physical layer (and thus no ethernet) is involved at all since localhost is just a logical but not a physical network interface.

The 65535 bytes limit in IP is because the length field in the IP header is only 16 bit.

Why an TCP packet is only 16388 bytes?

The applications sends data to the OS kernel which then packetizes the data. The size of the data which can be send to the kernel at once depend on the size of the socket buffer which results in the packet size you see. Additionally the kernel might further split the data to best fit the maximum size of the underlying physical layer (like ethernet). With TCP the kernel might also decide to join small data so that they get transmitted together.

Note that for TCP the packet length on the wire is actually irrelevant for the application since TCP is a continuous data stream. With UDP this would be different, i.e. every send would result in a single IP message and would also be received as such single message by the recipient.

4
  • Actually, IP attaches on top of a (data) link layer which is also the one doing the framing. The physical layer just transports bits and symbols.
    – Zac67
    Dec 20, 2020 at 12:50
  • @Zac67 There is no such thing in the TCP/IP networking model. TCP/IP does not use the OSI model. Mar 19, 2021 at 7:23
  • @SilverbackNet: Looks like there is some TCP/IP model. Otherwise it would be hard to compare this against the OSI model: en.wikipedia.org/wiki/OSI_model#Comparison_with_TCP/IP_model. There are even images which show the models in comparison. Just because it isn't OSI does not mean it don't exist. Mar 19, 2021 at 7:32
  • @SilverbackNet Steffen talks about the physical layer which only exists in OSI. The Internet model (RFC 1122) bunches it into its link layer.
    – Zac67
    Mar 19, 2021 at 7:48
7

Different data-link protocols were designed by different people at different times, and they each have their own MTU (maximum payload size). Ethernet was a college thesis for Bob Metcalfe, and it was designed with a 1500 octet MTU. This was about the time (1970s) that the predecessor for IP was being created by Vint Cerf. I seriously doubt either even knew the other or what the other was working on, and it is certain that neither knew that the other would become dominant, even after they were made products (ethernet in 1980 and IPv4 in 1981). Other people and other companies developed other data-link protocols, each with a different MTU specified by the protocol designer.

IP, and other network protocols, are the payload of the data-link protocol, so IP packets must fit inside the payload (MTU) of the data-link protocol. IP was designed with its maximum packet size because it was fast and easy to use a 16-bit number for the packet size. IPv4 has a 20 to 60 octet header that you must subtract from the packet size. IPv6 has a 40 octet header, and possible option headers.

A transport protocol, such as UDP or TCP is the payload of the network protocol. UDP has a datagram header size of 8 octets, and TCP has a segment header of at least 20 octets.

The network protocol and transport protocol headers must be subtracted from the data-link protocol MTU to arrive at the maximum amount of application data that can be transported inside a data-link frame. That would include any application-layer protocol, e.g. HTTP.


I guess the part that you are missing is that network protocols were basically all developed independently, by different people, with different ideas, at different times. What we use today are the protocols that became dominant over the years, for one reason or another. Many of these protocols have nothing to do with each other. For example, ethernet can carry any number of network protocols (IPv4, IPX, AppleTalk, IPv6, etc., ethernet was primarily used for IPX for years, which has nothing to do with IP), and neither IP version (IPv4 and IPv6) cares which data-link protocol (ethernet, Wi-Fi, ARCNET, token ring, FDDI, frame relay, HDLC, PPP, ATM, etc.) carries it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.