If you're preparing for your CCNA exam, or if you're just interested in networking, you probably want to learn about the differences between TCP and UDP as well as the origin of TCP/IP and OSI. This article explains the TCP and UDP protocols in computer networks so you can see the differences between the two. You will also find useful information concerning the protocol suite of the century: TCP/IP.
The TCP/IP model and OSI model
Both TCP/IP and OSI are suites of protocols that governs communication between applications on the internet. To understand UDP and TCP, let's start by comparing TCP/IP and the OSI Models.
What is the TCP/IP model?
The Transmission Control Protocol/Internet Protocol (TCP/IP) suite was created by the U.S. Department of Defense (DoD) to ensure that communications could survive any conditions and that data integrity wouldn't be compromised under malicious attacks.
What is the OSI model?
The Open Systems Interconnection Basic Reference Model (OSI Model) is an abstract description for network protocol design, developed as an effort to standardize networking.
TCP/IP model vs. OSI model
The TCP/IP model is basically a shorter version of the OSI model. It consists of four instead of seven layers. Despite their architectural differences, both models have interchangeable transport and network layers and their operation is based upon packet-switched technology. The diagram below indicates the differences between the two models:
Left: TCP/IP Model
Right: OSI Model
- Application Layer: The Application layer deals with representation, encoding and dialog control issues. All these issues are combined together and form a single layer in the TCP/IP model whereas three distinctive layers are defined in the OSI model.
- Host-to-Host: Host-to-Host protocol in the TCP/IP model provides more or less the same services with its equivalent Transport protocol in the OSI model. Its responsibilities include application data segmentation, transmission reliability, flow and error control.
- Internet: Again Internet layer in TCP/IP model provides the same services as the OSIs Network layer. Their purpose is to route packets to their destination independent of the path taken.
- Network Access: The network access layer deals with all the physical issues concerning data termination on network media. It includes all the concepts of the data link and physical layers of the OSI model for both LAN and WAN media.
TCP/IP Protocol Suite
Below is a diagram of the TCP/IP protocol suite. Note that in the Host-to-Host layer, Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are defined for transmitting datagrams. We will look at the details of both these protocols as well as their interaction with the upper layer.
Differences Between TCP and UDP
Now that we understand that the TCP and UDP are protocols within the host-to-host layer of the TCP/IP, we can start to examine some of their differences more closely.
What is TCP?
TCP is responsible for breaking down a stream of bytes into segments and reconnecting them at the other end, retransmitting whatever might be lost and also organizing the segments in the correct order. TCP is connection-oriented in the sense that end points need to establish a connection before transmission.
TCP protocol data units are called segments. The sending and receiving TCP entities exchange data in the form of segments, which consist of a fixed 20-byte header followed by a variable size data field. The segment size is restricted by the maximum transfer unit (MTU) of the underlying link layer technology (MTU is generally 1500 bytes which is the maximum payload size of the Ethernet).
The image below shows the TCP segment format. The most important fields are explained further on.
- Source Port and Destination Port fields together identify the two local end points of the particular connection. A port plus its hosts' IP address forms a unique end point. Ports are used to communicate with the upper layer and distinguish different application sessions on the host.
- The Sequence Number and Acknowledgment Number fields specify bytes in the byte stream. The sequence number is used for segment differentiation and is useful for reordering or retransmitting lost segments. The Acknowledgment number is set to the next segment expected.
- Data offset or TCP header length indicates how many 4-byte words are contained in the TCP header.
- The Window field indicates how many bytes can be transmitted before an acknowledgment is received.
- The Checksum field is used to provide extra reliability and security to the TCP segment.
- The actual user data appears after the end of the header.
What is UDP?
UDP (User Datagram Protocol) consists of fewer fields compared to TCP. The reason for that is because certain data types do not require reliable delivery and extra overhead. Real-time traffic for example, needs to be transported in an efficient way without error correction and retransmission mechanisms.
UDP is considered to be a connectionless protocol. It leaves reliability to be handled by the application layer. All it cares about is fast transmission. The UDP segment format is presented in the diagram below:
When should I use TCP vs. UDP?
Choosing the right transport protocol to use depends on the type of data to be transferred. For information that needs reliability, sequence transmission and data integrity -- TCP is the transport protocol to use. For data that require real-time transmission with low overhead and less processing -- transport protocol UDP is the right choice.
The following table summarizes the key-characteristics of each one of these protocols. Keep them in mind when choosing the transport protocol for your data.
Interested in tools for working with TCP and UDP protocols? Check out our list of Top 10 TCP/IP tools.
Segment retransmission and flow control through windowing
Want to learn more about TCP and UDP? Try Pluralsight's TCP and UDP Operation course!