36

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.

5
  • 7
    Wikipedia tells you everything you need to know in this case...
    – Artelius
    Commented Dec 4, 2009 at 10:24
  • 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 frame
    – Useless
    Commented Dec 4, 2009 at 10:33
  • Well.. and of course the IP frame if you want it to be routed.
    – halfdan
    Commented Dec 4, 2009 at 16:27
  • 1
    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
    Commented Dec 5, 2009 at 21:24
  • There is no such thing as an "IP frame": you probably want to be referring to an "IP packet".
    – jldupont
    Commented Dec 5, 2009 at 21:25

5 Answers 5

85

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

EDIT: the above incorrectly states the ethernet frame bytes as 24B. It's instead 18 (or 22 for VLAN-tagged ethernet). The 8B preamble is not part of the minimal-64B frame. So the minimum IPv4+TCP packet is 18+20+20=58 bytes, and minimal IPv4+UDP is 18+20+8=46 bytes. In those cases, there would need to be ethernet padding to fill the frame up to 64B (6B padding for the TCP example, 18B for the UDP example)

https://superuser.com/a/394413 agrees with this edit

8
  • 2
    this (modulo possible errors :) was indeed the overall result I was looking for indeed!
    – puccio
    Commented Dec 4, 2009 at 10:39
  • 8
    I think the minimum ethernet frame is 64 bytes (the payload must be padded to at least 46 bytes).
    – Useless
    Commented Dec 4, 2009 at 10:46
  • 2
    Not all TCP and UDP is carried on top of Ethernet, though - in fact the same packet may well be carried on several different physical layers during its transit across various networks.
    – caf
    Commented Dec 4, 2009 at 11:12
  • 3
    You are assuming that the IP server layer rides on top of Ethernet - a fair assumption for LANS, a lower probability one when it comes to the WAN.
    – jldupont
    Commented Dec 5, 2009 at 21:23
  • 3
    How Ethernet frame has 24 bytes? If I consider both mac and protocol the sum is 14 bytes, what is wrong with that assumption? Commented Nov 7, 2017 at 21:58
20

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:

3
  • 3
    does this also mean the following? 18(min. Ethernet "header" fields) + 18(padding) + 20(IPv4) + 8(UDP) = 64 bytes? In total 18+20+8 = 46 bytes for the IP+UDP payload.
    – Ali
    Commented Dec 8, 2014 at 5:19
  • 4
    Yes! Here again 20+8 (=28) is not enough for the minimum ethernet payload so 18 bytes of padding are needed (20+8+18=46).
    – Felix
    Commented Dec 9, 2014 at 9:55
  • In case you wonder how to distinguish an empty TCP packet from one with 1-6 bytes of payload on an ethernet, this is done using the "total length" field in the IP header. Commented Oct 24, 2017 at 14:43
9

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

1

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.

0

If you're looking for a software perspective (after all, Stack Overflow is for software questions) then the frame does not include the FCS, padding, and framing symbol overhead, and the answer is 54:

  • 14 bytes L2 header
  • 20 bytes L3 header
  • 20 bytes L4 header

This occurs in the case of a TCP ack packet, as ack packets have no L4 options.

As for FCS, padding, framing symbol, tunneling, etc. that hardware and intermediate routers generally hide from host software... Software really only cares about the additional overheads because of their effect on throughput. As the other answers note, FCS adds 4 bytes to the frame, making it frame 58 bytes. Therefore 6 bytes of padding are required to reach the minimum frame size of 64 bytes. The Ethernet controller adds an additional 20 bytes of framing symbols, meaning that a packet takes a minimum of 84 byte times (or 672 bit times) on the wire. So, for example, a 1Gbps link can send one packet every 672ns, corresponding to a max packet rate of roughly 1.5MHz. Also, intermediate routers can add various tags and tunnel headers that further increase the minimum TCP packet size at points inside the network (especially in public network backbones).

However, given that software is probably sharing bandwidth with other software, it is reasonable to assume that this question is not asking about total wire bandwidth, but rather how many bytes does the host software need to generate. The host relies on the Ethernet controller (for example this 10Mbps one or this 100Gbps one) to add FCS, padding, and framing symbols, and relies on routers to add tags and tunnels (A virtualization-offload controller, such as in the second link, has an integrated tunnel engine. Older controllers rely on a separate router box). Therefore the minimum TCP packet generated by the host software is 54 bytes.

Your Answer

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

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