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

  • maximum of an Ethernet packet is about 1500bytes.

  • maximum of an IP packet is about 65535bytes.

  • 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();


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--){
        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.
        System.out.println("message length is " + messageLength);

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

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.

| |

Browse other questions tagged or ask your own question.