34
votes

What is the size of an empty UDP datagram? And that of an empty TCP packet?

I can only find info about the MTU, but I want to know what is the "base" size of these, in order to estimate bandwidth consumption for protocols on top of them.

4
Wikipedia tells you everything you need to know in this case...Artelius
Artelius and halfdan are correct, but you're missing something: UDP and TCP both run on top of some physical transport. For example, if you're using UDP over ethernet, you should also include the size of the ethernet frameUseless
Well.. and of course the IP frame if you want it to be routed.halfdan
Which server layer? UDP on IP can ride on many server layers, one of which is Ethernet but there is also MPLS, PBT, Frame Relay, ATM, POS etc.jldupont
There is no such thing as an "IP frame": you probably want to be referring to an "IP packet".jldupont

4 Answers

81
votes

TCP:

Size of Ethernet frame - 24 Bytes
Size of IPv4 Header (without any options) - 20 bytes
Size of TCP Header (without any options) - 20 Bytes

Total size of an Ethernet Frame carrying an IP Packet with an empty TCP Segment - 24 + 20 + 20 = 64 bytes

UDP:

Size of Ethernet frame - 24 Bytes
Size of IPv4 Header (without any options) - 20 bytes
Size of UDP header - 8 bytes

Total size of an Ethernet Frame carrying an IP Packet with an empty UDP Datagram - 24 + 20 + 8 = 52 bytes

19
votes

Himanshus answer is perfectly correct.

What might be misleading when looking at the structure of an Ethernet frame [see further reading], is that without payload the minimum size of an Ethernet frame would be 18 bytes: Dst Mac(6) + Src Mac(6) + Length (2) + Fcs(4), adding minimum size of IPv4 (20) and TCP (20) gives us a total of 58 bytes.

What has not been mentioned yet is that the minimum payload of an ethernet frame is 46 byte, so the 20+20 byte from the IPv4 an TCP are not enough payload! This means that 6 bytes have to be padded, thats where the total of 64 bytes is coming from.

18(min. Ethernet "header" fields) + 6(padding) + 20(IPv4) + 20(TCP) = 64 bytes

Hope this clears things up a little.

Further Reading:

9
votes

See User Datagram Protocol. The UDP Header is 8 Bytes (64 bits) long.

The mimimum size of the bare TCP header is 5 words (32bit word), while the maximum size of a TCP header is 15 words.

Best wishes, Fabian

0
votes

If you intend to calculate the bandwidth consumption and relate them to the maximum rate of your network (like 1Gb/s or 10Gb/s), it is necessary, as pointed out by Useless, to add the Ethernet framing overhead at layer 1 to the numbers calculated by Felix and others, namely

  • 7 bytes preamble
  • 1 byte start-of-frame delimiter
  • 12 bytes interpacket gap

i.e. a total of 20 more bytes consumed per packet.