TCP versus UDP

tcp-vs-udp-comparison-ipcisco.com

TCP vs UDP

Before, we have talked about TCP and UDP as an overview. In this CCNA Certification Lesson, we will compare these two transport layer protocols and we will learn their main characteristics. In other words, we will compare  TCP vs UDP, we will learn what is the difference between TCP and UDP. This comparison is very important in networking world and it is generally a Network Engineering Technical Interview Question. This lesson is also an important lesson for network engineering certification exams. Because, there are critical questions are coming from this lesson on certification exams.

 

By the way, there is also another transport layer protocol named SCTP (Stream Control Transmission Protocol). After learning the difference between TCP and UDP, we will also compare SCTP and TCP in another lesson. We will learn SCTP vs TCP. But here, our focus is not SCTP but the other two transport protocols.

 

Below, you can find a table that compares TCP vs UDP. We will also explain each line for you detailly. According to the latest developments on these transport protocols, our comparison table is renewed.

the-difference-between-TCP-and-UDP-ipcisco

 

(Below, you can find the previous old comparison tables)

tcp-versus-udp

 

So, what is tcp and udp difference? Let’s explain one by one.

 

Let’s firstly start with the full name of these transport layer protocols. TCP stands for Transmission Control Protocol while UDP stands for User Datagram Protocol.

 

The first difference of TCP vs UDP comparison is about connections and sessions. In User Datagram Protocol, you do not need a connection, so it is a connectionless transport protocol. But Transmission Control Protocol needs a connection. In other words, a connection must be established for the communication of this protocol. So, TCP is a connection-oriented protocol. This connection is done with TCP 3-Way Handshake. with SYN, ACK and SYN-ACK messages.  And this connection is termianted with TCP 4-Way Handshake, with FIN and ACK messages from both sides.

 

How about TCP vs UDP speed comparison? If we compare speeds, whatis the difference between TCP and UDP?If we compare the speeds of these two protocols, this time UDP (User Datagram Protocol) wins, because it is faster than TCP. It needs less actions to send data, because it is connectionless and it has no ACK mechanism for guaranteed transfer. TCP is slower than UDP because of its additional mechanisms. So, if you need a fast communication and if some losses are not important for you, you can use User Datagram Protocol. But if guaranteed transfer is the number one case for you, then you should use Transmission Control Protocol even it is slower than UDP.

 

 

Now, let’s talk about reliability and compare TCP vs UDP. TCP is a reliable protocol. Because, TCP guarantees the delivery of the data with ACK mechanism. If any segment does not reach to the destination and the sender does not receive an ACK in a certain time, it resends the segment again. UDP has no such an ACK mechanism. So, UDP does not guarantee the data delivery. This means that, UDP is a little an unreliable transport protocol.

 

Another difference between TCP and UDP is about ordering mechanism. In TCP session, sometimes packets can be sent in different orders. So, if we do not do anything, the inordered packets will be meaningful at the other end. We should reorder these packets. Transmission Control Protocol has a mechanism that reorders these packets at the receiver end. But UDP has no such a reorder mechanism. By using reordering mechanism, TCP makes this message meaningful.

 

Beside reordering mechanism, TCP also has Flow Control, Window scaling. It dynamically sets the window size for the optimum transmission. There is no such a flow control in UDP.

 

TCP provides extensive error checking mechanism which are not used in User Datagram Protocol. In other words, TCP uses error checking and recovery mechanism together. But UDP uses basic checksums for error checking. So, it is susceptible to the data loses. Generally, applications that uses UDP, provide its own error-recovery.

 

How about the headers? How about their sizes? When we compare TCP vs UDP, there is a big difference also about the length of the headers. TCP Header is 20 Bytes long and this value can be increased up to 60 bytes with option fields. But UDP Header is fixed 8 Bytes long.

 

As security mechanims, SSL/TLS (Transport Layer Security) is used by TCP. While DTLS (Datagram Transport Layer Security) is used by UDP. With these mechanism both protocols can be secure at a level.

 

By the way, TCP is used in Critical applications like file transfers, secure web etc because it is slower but there is guaranteed transfer. But User Datagram Protocol has no guranteed transfer mechanism butit is faster. So, UDP is used in real-time applications like voice services, live conferences, online games. 

 

Beside these differences, different protocols and applications use different TCP and UDP Port Numbers. For example, HTTP, HTTPS and FTP use TCP ports while DHCP, TFTP and SNMP use UDP ports by default. These default port numbers are also asked too much in the network engineering job interviews and in the network certification exams. Now, let’s talk about these default ports and learn them detailly.


 

TCP and UDP Application Ports

In networking, different ports are used for various purposes. Generally, these network port ranges can be divided into three categories. Below, you can find these port ranges:

  • Well-Known Ports ( 1 to 1024 )
  • Registered Ports ( 1025 to 49151 )
  • Private Ports ( 49152 to 65535 )

 

The applications which use TCP Protocol (Transmission Control Protocol) and UDP Protocol (User Datagram Protocol) use some of these Well-Known Ports. They use only TCP ports, only UDP port or they use ports of both.

 

Let’s see, some of these Well-Known Network Ports and compare TCP vs UDP ports. 

 


 

TCP Well-Known Ports

We have compared TCP vs UDP and we have learned the differences between these two protocols. Now, let’s do UDP vs TCP for ports. For UDP and TCP default port comparison, let’s firstly learn the protocols which use only TCP ports. In other words, there are some Applications that use Transmission Control Protocol (TCP) . Some of these protocols are given below:

  • FTP Data (Port 20)
  • FTP Control (Port 21)
  • SSH (Port 22)
  • Telnet (Port 23)
  • SMTP (Port 25)
  • TACACS (Port 49)
  • HTTP (Port 80)
  • POP3  (Port 110)
  • SFTP (Port 115)
  • HTTPS (Port 443)

protocols-uses-tcp-ports-ipcisco

 

Beside these protocols, Gopher, Finger, NNTP, IMAP, LDAP, Quick Mail Transfer protocols use also TCP ports by default. Gopher uses port 70, Finger uses port 79 by default. Network News Transfer Protocol (NNTP) uses port 119, Internet Message Access Protocol (IMAP) uses port 143, Lightweight Directory Access Protocol (LDAP) uses port 389 and Quick Mail Transfer Protocol uses port 209 by default.

  • Gopher uses port 70
  • Finger uses port 79
  • Network News Transfer Protocol (NNTP) uses port 119
  • Internet Message Access Protocol (IMAP) uses port 143
  • Quick Mail Transfer Protocol uses port 209
  • Lightweight Directory Access Protocol (LDAP) uses port 389

 

UDP Well-Known Ports

Secondly, let’s talk about the protocols which use only User Datagram Protocol (UDP) Ports. Some of these protocols are given below:

  • DHCP & BOOTP Server (Port 67)
  • BOOTP User (Port 68)
  • TFTP (Port 69)
  • NTP (Port 123)
  • SNMP (Port 161)
  • SNMP Trap (Port 162)
  • Syslog (Port 512)
  • ISAKMP (Port 500)

udp-only-ports-ipcisco

 

There are also other protocol that uses UDP ports by default. One of the old but well-known routing protocols, Routing Information Protocol (RIP), uses UDP port 520 by default.

The other important protocol for clock synchronization, PTP (Precision Time Protocol). PTP uses UDP  319, 320 ports by default.

 


 

TCP/UDP Well-Known Ports

Now, let’s talk about the protocol that use both UDP and TCP ports. There are different protocols and applications use both TCP and UDP ports. One of the well-known network protocols which use both TCP and UDP ports is DNS. DNS uses TCP and UDP port 53. It uses the same port of both of these protocols.

 

There are also other application which use both of these protocols according to the need. Here, we have talked about some of these well-known protocols only.

 


 

You can find the whole list of these ports at the IANA Website. In this list you can also see the ports of other Trasport Layer protocols, Stream Control Transmission Protocol (SCTP) and Datagram Congestion Control Protocol (DCCP) beside UDP and TCP.

In this lesson, we have compared the most improtant transport layer protocols, we have compared TCP vs UDP. To learn more about these transport layer protocols, you can also check the specific lessons of these protocols.

 


Below,  you can find some key questions about the difference of TCP and UDP. You can access also the lesson questions at the end of this page below.


The Difference Between TCP and UDP Header

One of the key difference between TCP and UDP is about their headers. TCP header and UDP header has different header length and different parts. The length of TCP header is variable and 20-60 bytes while the length of UDP header is fixed 8 bytes. Let’s check also these header parts one by one to see the difference.

TCP Header Format:

  • Source Port (16 bits)
  • Destination Port (16 bits)
  • Sequence Number (32 bits)
  • Acknowledge Number (32 bits)
  • Length (4 bits)
  • Reserved Bits (3 bits)
  • Flags (9 bits)
  • Window Size(16 bits)
  • Checksum (16 bits)
  • Urgent Pointer (16 bits)
  • Options (0 to 320 bits.)
tcp-header-ipcisco, TCP protocol header format

TCP Header Format

UDP Header Format:

  • Source Port (16 bits)
  • Destination Port (16 bits)
  • Length (16 bits)
  • Checksum (16 bits)
udp-header, UDP protocol header format

UDP Header Format


 

TCP and UDP Questions

Questions 1: How many bytes are there in an TCP and UDP Headers in order?

a) 4/16

b) 16/4

c) 8/20

d) 20/8

e) 8/16


Questions 2: When we compare TCP vs UDP, which one has no Handshake mechanism?

a) TCP

b) UDP


Questions 3: Which ones are True for TCP but not UDP? 

a) There is no ACK mechanism

b) Secure transport protocol

c) Provide guaranteed transfer

d) Fast protocol

e) Has 8 bytes header


Questions 4: Which ones are True for UDP but not TCP? (Select 2)

a) Slow protocol

b) Secure transport protocol

c) No Reorder mechanism

d) There is no ACK mechanism

e) Has 20 bytes header


Questions 5: Which ones are Well-known ports range?

a) 1-1024

b) 1025-49151

c) 49152-65535


Answers: 1)d   2)b   3)c   4)c,d   5)a

Lesson tags: tcp, udp
Back to: CCNA 200-301 v1.1 > TCP and UDP

Leave a Reply

Your email address will not be published. Required fields are marked *

CCNA 200-301 v1.1

Collapse
Expand
Latest Blog Posts