Difference between TCP and UDP

TCP full meaning Transmission Control Protocol is connection oriented, whereas UDP full meaning User Datagram Protocol is connection-less. 

Connection-orientation is that the communicating devices should establish a connection before transmitting data and should close the connection after transmitting the data. Datagram protocol means there is no overhead for opening a connection, maintaining a connection and terminating a connection. 

Difference : 
  • There is acknowledgment for each byte so we called TCP a byte stream protocol on the other side no acknowledgment in UDP. 
  • Because of Acknowledgments, TCP is considered reliable data transfer protocol while UDP is unreliable.
  • TCP is heavyweight whereas UDP is lightweight. 
  • Header size of TCP is 20 bytes and UDP header size is 8 bytes. 
  • Retransmission of lost packets is possible in TCP, but not possible in UDP. 
  • Segment sequencing of data is a feature of TCP and no such feature for UDP. 
  • Because of an upper feature, TCP gives a guarantee that the order of data at receiving end is the same as on sending end whereas UDP has no such guarantee.
  • TCP is used by HTTP, HTTPs, FTP, SMTP and Telnet, and UDP is used by DNS, DHCP, TFTP, SNMP, RIP and VOIP. 
  • TCP require much more computer resources while UDP require less computer resources.
  • UDP is much faster than TCP.
  • UDP is faster in data transferring than TCP.
  • TCP support full duplex while UDP not.
  • TCP is safer than UDP.
  • Flow control, congestion control happen in TCP while UPD both are not happening.  
  • TCP arranges data packet in an order specified while UDP protocol no inherent ordering, the data packets of the same message may be ordered differently.
  • TCP makes a check for error and reporting while UDP makes error checking but no reporting.
  • TCP follows 3 way of handshakes for connection establishment whereas no handshake is required in UDP since it is connectionless protocol. 
  • Example of TCP: Making a phone call Example of UDP: Playing online games. 
Handshake of TCP : 
  1. SYN
  2. SYN-ACK
  3. ACK
Field of TCP : 
  1. Sequence number 
  2. AcK number 
  3. Data offset 
  4. Reserved 
  5. Control bit 
  6. Window
  7. Urgent Pointer 
  8. Options
  9. Padding
  10. Checksum 
  11. Source port 
  12. Destination Port 
Field of UDP : 
  1. Length
  2. Source Port
  3. Destination Port
  4. Checksum