Difference Between TCP and UDP Protocols | Brief with Real-Time Examples

TCP vs UDP: Differences Between TCP & UDP Protocols

what is the difference between TCP and UDP

The Transport Layer is responsible for data transfer and ensures reliable and error-free delivery to the destination. The Transport Layer is the Host-to-Host layer in the Department of Defense OSI Model.

There are two categories of the Transport Layer:

Connection-Oriented Protocol (TCP)

This means that when data is transferred from source to destination, a connection is established before data is sent, based on agreed-upon parameters.

Connectionless Protocol (UDP)

This means that when data is transferred from source to destination, there is no need for agreed-upon parameters to establish the connection. The data is sent directly to the destination.

Connection-oriented protocols provide several important services:

Connections are established, maintained, and terminated between two devices.

Data is segmented into smaller chunks, and sequence numbers are assigned to verify its order upon arrival.

When data is sent to the destination, an acknowledgment is sent to confirm its delivery. If data is lost during transmission, it will be retransmitted.

Data transfer is regulated to ensure smooth transmission and prevent congestion.

Port Numbers and Sockets

TCP and UDP provide mechanisms for running data on the same host by differentiating port numbers. When a host receives a segment, the port number informs the transport layer which higher layer application should handle the packet. The port number range is from 0 to 65535 for both TCP and UDP.

Socket

An IP address and port number combination is called a socket, which differentiates hosts and services. For example, in 192.168.60.15:443, 192.168.60.15 is the IP address, and 443 is the port number. The range from 0-1023 is reserved for widely used services known as well-known ports.

Below is the table where you can see the port number, Protocol, and the Application

Port Number Transport Protocols Applications
20,21 TCP FTP
22 TCP SSH
23 TCP Telnet
25 TCP SMTP
53 UDP or TCP DNS
80 TCP HTTP
110 TCP POP3
443 TCP SSL
666 TCP Doom

What is Network Topology? Types and Diagrams Explained

What is Transmission Control Protocol (TCP)

The Transmission Control Protocol (TCP) is a connection-oriented protocol responsible for reliable delivery from source to destination. In the early days, TCP and IP worked together to make its core function, but it was inflexible. Additionally, TCP works on the Transport Layer, and IP works on the Network Layer. This separation is in version 4 of TCP, defined in RFC 793.

Let’s take one example of the connection-oriented protocol.

TCP is a three-way handshake connection between two hosts.

  • Host A sent a SYN message to Host B to make the connection
  • Host B sent an ACK message to Host A, and SYN+ACK becomes a single message forwarded to Host A
  • Host A completes the three-way handshake by sending ACK to Host B SYN.

Real-Time Examples
Whatsapp, Instagram, Google Chat,iMessage, FTP, Telnet

The TCP Header

Total size of the TCP is 20 Bytes (160 bits) along with 12 fields

Field Length Description
Source Port 16-Bits Source TCP Port
Destination Port 16-Bits Destination TCP Port
Sequence Number 32-Bits Sequence Number
ACK Number 32-Bits Acknowledgement Number
Data Offset 4-Bits Shows the begin of TCP Segment
Reserved 6-Bits Always set to 0
Control Bits 6-Bits URG,ACK,PSH,RST,SYN and FIN Flags
Window 16-Bits Used for flow control
Checksum 16-Bits Used for Error Checking
Options Variable  
Padding Variable To ensure the TCP Header end with 32-Bit

What is User Datagram Protocol (UDP)

ser Datagram Protocol is a connectionless protocol on the Transport Layer that is defined in RFC 768. Further, In UDP, there is no mechanism for a three-way handshake, no flow control, no acknowledgment, no sequence number. It is an unreliable protocol; it just forwards the packet and then takes no action on it.

Real-Time Examples
Online Games, Media Streaming, Voice over IP (VoIP)

The UDP Header

Field Length Description
Source Port 16-bits Source UDP Port
Destination Port 16-bits Destination Port
Length 16-bits Size of the Header and data
Checksum 16-bits Used for Error Checking

Key Difference Between TCP and UDP Protocol

TCP UDP
Also, Perform CRC Connectionless
Guarantee Delivery No Guarantee
Send Acknowledgment No ACK
Reliable but slow Unreliable but fast
Segment and sequence No segment and sequence
Resend dropped packets Not resend
Provide Flow Control No
Perform CRC on data Also Perform CRC
Used Port Number Also Used Port Numbers

This Post Has One Comment

Leave a Reply