So I'm reading Computer Networking: A top down approach (where these images are from) and I was looking at the Transport layer.

A generic segment in the transport layer has a pretty simple structure: source port, destination port, some other header fields, and application data.

Then comes UDP and TCP, which are also from the transport layer, but have some differences in how they're handled and all of that.

Looking at the images bellow, there's really no field where the segment can be identified as TCP or UDP, right?

So when the PC tries to demultiplex the segment into the respective socket, how does it know whether it is UDP or TCP?

enter image description here enter image description here enter image description here

  • Please take care about the "generic segment structure": Apart from UDP and TCP there are other transport layer protocols like GRE. These protocols do not necessarily have "source port" and "destination port" fields. And if they do have, it is not guaranteed that the port numbers are 16 bits wide, and if they are, it is not guaranteed that they are located in the first 32 bits of the segment. Commented Jan 19, 2019 at 21:44
  • So that information is always stored in the underlying layer and transmitted to the transport layer?
    – Lucas
    Commented Jan 20, 2019 at 22:09
  • 1
    The type of layer-4 protocol is always stored in the IP header (layer-3 header). When an IP packet arrives, the IP software is responsible for calling the UDP software, TCP software or GRE software etc. Therefore the information if the packet is a UDP or a TCP packet is needed by the IP software, not by the TCP or UDP software. For this reason it makes sense to store it in the IP header. Commented Jan 21, 2019 at 6:17

1 Answer 1


IP knows. For IPv4 there is a 8bit protocol field where 6 represents TCP and 17 UDP. In IPv6 there is an equivalent next-header.

You can see all reserved protocol types here: https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml


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.