I know that both TCP and UDP are built on top of IP, and I know the differences between TCP & UDP, but I'm confused about what exactly "raw ip" is. Would it be fair to say that TCP & UDP both implement IP, but that IP in and of itself isn't capable of transferring data? Or is IP some very low level form of communication, which is further abstracted by TCP and UDP?

  • 2
    To further some of the comments below (not enough for a full answer, just for the sake of clarity): IP is a protocol that transports data. TCP or UDP are protocols that transport data too. TCP and UDP often sit on top of IP so for IP it's data payload can be TCP or UDP. Ethernet is often used to carry IP. So for example an Ethernet frame may carry and IP packet as it's data payload and that IP packet maybe carrying a TCP segment as it's payload, and so on. You end up with a stack of protocols like this goo.gl/1uEYtC
    – Baldrick
    Feb 15, 2016 at 20:59
  • 3
    IP certainly does transfer data - it carries those TCP/UDP packets, for example. It's not usually application-usable, though. UDP is a very raw protocol on top of IP, but it already adds port numbers, allowing multiple services to handle UDP traffic concurrently on a system. Otherwise, you'd only have as many services as you have IP addresses.
    – Luaan
    Feb 15, 2016 at 22:00

3 Answers 3


IP is a Layer 3 protocol. TCP/UDP are Layer 4 protocols. They each serve different purposes.

Layer 3 is in charge of end to end delivery. Its sole function is adding whatever is necessary to a packet to get a packet from one host to another.

Layer 4 is in charge of service-to-service delivery. Its sole function is to segregate data streams. Your computer can have multiple programs running, each which sends/receives bits on to the wire. IE: You could have multiple browser tabs running, streaming internet radio, running a download, running some legal torrents, using a chat application, etc. All of these receive 1s and 0s from the wire, and Layer 4 segregates each data streams to the unique application that needs them. Here is an illustration:

L4 segregating Data Streams

IP is unable to deliver a packet to the correct service/application. And TCP/UDP is unable to deliver a packet from one end of the internet to the other.

Both TCP and IP work together to enable them both to achieve the "end-goal" of Internet communication.

Data that needs to get from one host to another is generated by the upper layers of the OSI model.

This data is passed down to L4 which will add the information necessary to deliver the data from service to service, like a TCP header with a Source and Destination Port. The Data and the L4 header is now referred to as a segment.

Then the Segment will be passed to L3 which will add the information necessary to deliver the segment from end to end, like an IP header with a Source an Destination IP address. The L3 header and the segment can now be referred to as a Packet.

This process is known as Encapsulation and De-encapsulation (or sometimes decapsulation). Here is an animation of how it works:

Encapsulation and De-encapsulation, used with permission from Practical Networking.net

If this doesn't make sense, I suggest reading more about the OSI model, and how each layer has different responsibilities that all work together to accomplish moving a packet across the Internet.

  • 7
    Note that the Internet only loosely follows the OSI model.
    – user253751
    Feb 16, 2016 at 2:33
  • 2
    inside an IP header is usually a TCP or UDP header is not correct, the TCP/UDP header is not inside the IP header, it's inside the data portion of the IP packet.
    – Eborbob
    Feb 16, 2016 at 10:50
  • 1
    "Its sole function is to segregate data streams", while that is mostly true for UDP (there is also a checksum but meh) it is certainly not true for TCP. Feb 16, 2016 at 17:57
  • 1
    @immibis True, but I have yet to see where following the OSI model has lead to a gaping implementation or understanding travesty. For the most part, and especially for someone newly approaching Internet technologies, its more valuable to continue thinking along the constrains of the OSI model.
    – Eddie
    Feb 16, 2016 at 18:25
  • @Eborbob I can see how its wrong depending on how look at the sentence. Honestly, that whole paragraph could use a reword, I'll try to get to it later tonight. Thanks for pointing it out.
    – Eddie
    Feb 16, 2016 at 18:26

IP can transmit data just fine, the problem is what happens when that data gets to the other end. The only identification information is the IP addresses of the hosts and a protocol number. Neither of which provide any way to distinguish what socket the data is for.

It is possible for programs to use IP directly through what are known as "raw sockets" but the lack of a proper mechanism for deciding which socket to send data to raises security and performance concerns (the kernel has to send the data to all raw sockets for a given protocol number). For this reason the ability to open "raw sockets" is usually restricted to root (or your platform's equivilent).

UDP is a fairly minimal layer over IP. It adds port numbers to identify what socket the data is for and a checksum (to reject corrupt packets). The application remains responsible for dealing with lost packets, controlling congestion and splitting the data into appropriate sized packets.

TCP is a more complex protocol that in addition to providing port numbers and checksums splits byte-streams into packets, reassembles then at their destination and provides congestion control and recovery features.

  • Of all the articles and writings on this subject on the internets, this answer distills everything down to the truth that matters.
    – JamesHoux
    Feb 23, 2023 at 3:37

IP is an OSI layer-3 protocol, while TCP and UDP are OSI layer-4 protocols. As a layer-3 protocol, IP can carry many different layer-4 protocols. TCP and UDP are probably the most common, but they are not the only ones. Layer-4 protocols are what applications use as their end-to-end connections. IP transports layer-4 protocols from network to network (host-to-host). Layer-2 protocols, like ethernet, transport layer-3 protocols on a LAN.

You should research the OSI model, but realize that it is a conceptual model, and the real world often doesn't exactly match.

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.