Home > TCP and UDP Tutorial

TCP and UDP Tutorial

September 20th, 2016 Go to comments

The Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are the two most popular protocols in the transport layer. They ensures that messages are delivered error-free, in sequence, and with no losses or duplication. The key difference between TCP and UDP is that TCP provides a wide variety of services to applications, whereas UDP does not. At the result of this, TCP is much more complex than UDP so this tutorial is dedicated to explore TCP in detail but we still compare them.


Both TCP and UDP are protocols at the Transport layer (of both OSI and TCP/IP model) but why we need both of them? The answer is:

+ TCP is slower but reliable
+ UDP is faster but unreliable

In most cases we will want to be reliable in web accessing, email communicating, file uploading… as we don’t expect a few corrupted packets would destroy our whole work. With TCP, these corrupted packets will be resent or repaired to make sure everything is correct. Yes, TCP is really nice to ensure your work is accurate!

But with a price…

To guarantee the sending segments is free of error, TCP adds some bits for tracking and checking purpose so that the other end can verify and ask for missing pieces of segments. As a result of this, the segments become larger, consume more bandwidth and CPU resources to proceed.

Although UDP cannot guarantee everything is accurate like TCP but UDP is faster than TCP because it does not require additional bits for tracking and checking purpose. So which tasks need speed? Video (streaming) and audio are ideal for this task because they are considered real-time applications. Suppose you are talking to your friend, surely you want your voice to reach your friend without any delay. It would be very weird if your friend can only hear your voice after a few seconds.

Note: Segment is the name of the data packet at Transport layer

TCP can also slow down the transmission if it sees the path to the destination is too crowded. You don’t want TCP to slow down your voice in traffic-jam hours either. For example when you say “Hello, how are you?”, your friend at the other end may hear “Hellooooo,…… hooooooooow arrrrrrrre yyyyyoou”. What is an awful conversation!

Losing a few packets for voice or video is acceptable. For example if you say the word “Hello” in one second, an IP phone generates about 25 to 100 packets (just an estimation, it depends on the codec and sampling frequency) so your friend can still understand what you say even if a few packets are missing. Moreover, re-transmission the missing packets is not useful as voice and video are real-time applications and the receiving end cannot wait for the missing segments to be resent.

So now we have some basic understanding of TCP and UDP. In the next part we will learn more about TCP. Let’s start with how TCP set up and terminate a connection.

TCP three-way handshake (to start the communication)

Suppose host A wants to start communicating with host B using TCP. Before they can send real data, a three-way handshake must be established first. Let’s see how this process takes place:


1. First host A will send a SYN message (a TCP segment with SYN flag set to 1, SYN is short for SYNchronize) to indicate it wants to setup a connection with host B. This message includes a sequence (SEQ) number for tracking purpose. This sequence number can be any 32-bit number (range from 0 to 232) so we use “x” to represent it.

2. After receiving SYN message from host A, host B replies with SYN-ACK message (some books may call it “SYN/ACK” or “SYN, ACK” message. ACK is short for ACKnowledge). This message includes a SYN sequence number and an ACK number:
+ SYN sequence number (let’s called it “y”) is a random number and does not have any relationship with Host A’s SYN SEQ number.
+ ACK number is the next number of Host A’s SYN sequence number it received, so we represent it with “x+1”. It means “I received your part. Now send me the next part (x + 1)”.

The SYN-ACK message indicates host B accepts to talk to host A (via ACK part). And ask if host A still wants to talk to it as well (via SYN part).

3. After Host A received the SYN-ACK message from host B, it sends an ACK message with ACK number “y+1” to host B. This confirms host A still wants to talk to host B.

If you are still unclear about this process, let’s assign: x = 1 and y = 50:


In this process, three messages need to be sent so we often call it “three-way handshake”.

Nice, now you really understand TCP three-way handshake, right? Host A can start sending real traffic to host B after the three-way handshake process.

TCP also does nearly the same thing when one end wants to terminate the connection with TCP four-way termination process.

TCP four-way termination (to end the communication)


Suppose Host A wants to end the connection to host B, Host A will send a FIN message (a TCP segment with FIN flag set to 1), FIN is short for FINISH. The purpose of FIN message is to enable TCP to gracefully terminate an established connection. Host A then enters a state called the FIN-WAIT state. In FIN-WAIT state, Host A continues to receive TCP segments from Host B and proceed the segments already in the queue, but Host A will not send any additional data.

Device B will confirm it has received the FIN message with an ACK (with sequence x+1). From this point, Host B will no longer accept data from Host A. Host B can continue sending data to Host A. If Host B does not have any more data to send, it will also terminate the connection by sending a FIN message. Host A will then ACK that segment and terminate the connection.

TCP requires to establish and terminate the connection before and after exchanging real traffic so it is called connection-oriented protocol. UDP does not support these features so it is called connectionless protocol.

More formally, these terms can be defined as follows:
+ Connection-oriented protocol: requires a logical connection to be established between the two processes before data is exchanged
+ Connectionless protocol: allow data to be exchanged without setting up a link between processes

In conclusion, TCP requires the establishment (via three-way handshake) and termination (via four-way termination) of a connection. In the next part we will learn about popular TCP features.

Comments (50) Comments
Comment pages
  1. KR
    August 12th, 2017

    Very good article 9tut. Gets into the nitty gritty details which will enhance a network admins knowledge.

  2. Plz send ccna v3 dumps which is valid Thank u so much
    August 16th, 2017

    {email not allowed}

  3. Plz send ccna v3 dumps which is valid Thank u so much
    August 16th, 2017

    samihussain.77 AT gamil.com

  4. Plz send ccna v3 dumps which is valid Thank u so much
    August 16th, 2017

    samihussain.77 AT gmail.com

  5. Alaa
    August 21st, 2017

    I got the last CCNA(200-125) dump V30 (401 Questions),you can download it from the below link :

  6. nagi
    August 22nd, 2017

    can any one send me the latest ccna 200-125 as i have to give the exam soon nagikhalil9@gmail(dot)com

  7. VK
    August 26th, 2017

    Hi Please send me latest ccna v3 dumps :{email not allowed} Please!!

  8. VK
    August 26th, 2017

    Hi All Please send me latest ccna v3 dumps to zzntlathi at gmail dotcom

  9. Anonymous
    August 27th, 2017

    beautifully written article,worth reading.

  10. Kahsay
    August 29th, 2017

    Hi Aaa thank you for the link you provide us! It’s really very valuable.
    Thank you again!

  11. Anonymous
    August 31st, 2017


  12. Latest Dumps
    August 31st, 2017

    http:// r1x.pw/vyfkRL

    CCNA V3 Dumps. Thank me later.

  13. mbfn
    September 1st, 2017

    anyone send ccna dumb latest for my mail {email not allowed}

  14. mbfn
    September 1st, 2017

    send ccna dump for my gmail. mbfazlinisar

  15. martianradio
    September 6th, 2017

    site for secure valid dump?

  16. ayman karrar
    September 10th, 2017

    thank you for the link you provide us! It’s really very valuable

  17. Anonymous
    September 13th, 2017

    Hi! If anyone have a latest version of ccna dump please send me willon95@gmail(dot)com

  18. J
    September 22nd, 2017

    pls send me the latest dumb {email not allowed}

  19. Amal Alexander
    September 24th, 2017

    Can anyone please send me ICND-1 (100-105) dumps.
    {email not allowed}

    Thank You…..

  20. Amal Alexander
    September 24th, 2017

    amalalexander07 AT gmail.com

  21. samuel
    September 27th, 2017

    can someone assist me too please with the current CCNA dumps. at {email not allowed}

  22. xxErmis
    September 27th, 2017

    Great post, loved it

  23. Alina
    September 27th, 2017

    updated and valid questions. just passed using these dumps.

  24. halil
    October 6th, 2017

    Hello, My name is halil;
    I need CCNA questions, Could you help..

    halilalban at outlook dat com

  25. Can any body send latest ccnx dumbs?
    October 15th, 2017

    Can anybody send latest ccnx dumbs?

  26. shruti
    October 18th, 2017

    can anybody plz send me the updated dumps on my id { shrutiagarwal2727 @ gmail.com} . your help will be really appreciated.

  27. Anonymous
    October 29th, 2017

    can someone please send me CCNA DUMPS
    paul.chavez2526 AT Gmail.com

  28. Anonymous
    October 30th, 2017

    can someone please send me CCNA exam hints

    October 30th, 2017

    Can someone send me the latest dumps
    scast91121 at gmail.com

  30. alam
    October 31st, 2017

    please please please someone send me latest dumps for ccna 200-125 exam !!
    sifat0617 at gmail.com

  31. KT
    November 8th, 2017

    Can someone send me some CCNP route and Switch Dumps please. kimdctorres @ gmail.com

  32. NH
    November 8th, 2017

    Can someone send me the latest valid dumps please on my e-mail : {email not allowed}

  33. Excel
    November 9th, 2017

    Please will really appreciate someone send me a recent study guide for CCNA 200-125 and dumps too. email: {email not allowed}

  34. Excel
    November 9th, 2017

    Please will really appreciate someone send me a recent study guide for CCNA 200-125 and dumps too. wealthmachine2016 at gmail.com

  35. Anonymous
    November 10th, 2017

    pls someone send me ccna 200-125 lastest dumps to my gmail {email not allowed}

  36. KeyWest
    November 11th, 2017

    To the author of this website there is an error regarding NTP.

    There is a mistake NTP is a UDP protocol not TCP protocol..

    The above table about well known TCP ports :-
    NTP is a UDP port
    NTP is not a TCP port..

    Todd Lammle Book CCNA 200-125 pg 107,
    NTP is under UDP table

  37. 9tut
    November 11th, 2017

    @KeyWest: Yes, thanks for your detection. We fixed this error.

  38. LAN
    November 13th, 2017

    what ccnp routing and switching code comes after ccna 200-125…is it ccnp 300-101?

  39. samson
    November 14th, 2017

    can anyone kindly send me the updated dumps on my id { apexcomke @ gmail.com} . your help will be really appreciated.

  40. Kent
    November 14th, 2017

    can someone please send me CCNA DUMPS

  41. Unkown
    November 28th, 2017

    Please can anyone send me CCNA DUMPS , i want to take the exam as fast as possible , i failed in th first take :(
    Please send me on zemer . kuksiani@ gmail.com

  42. Adrian
    November 29th, 2017

    can anyone send me ccna 200-125 dumps. thank you in advance.
    adrianmatias14 @ gmail.com

  43. jose pedro
    November 29th, 2017

    are those bump question free or you need to buy them as well?

  44. Anonymous
    December 1st, 2017

    please anyone send me ccna 200-125 dumps.
    {email not allowed}

  45. Carlos
    December 5th, 2017

    Passed, if you go the exam study the 552q dumps.

  46. Anonymous
    December 19th, 2017

    Hi Geraldo,

    There are several docs here. Which one specifically? Thanks

  47. wyatt eirp
    December 25th, 2017

    pass latest dumps to wyatt.eirp777 AT gmail DOT com

  48. Emma Roberts
    December 27th, 2017

    www. dumps*for*sure.com
    Visit to pass your exam with 100% passing guarantee.

  49. Anonymous
    December 28th, 2017

    nice note

  50. stiven
    January 9th, 2018

    correct answer plzzz????

    01.If you configure syslog messages without specifying the logging trap level, which log
    messages will the router send?

    A. error conditions only
    B. warning and error conditions only
    C. normal but significant conditions only
    D. all levels except debugging
    E. informational messages only

    02.Which function does the IP SLAs ICMP Echo operation perform to assist with

    A. hop-by-hop response time
    B. packet-loss detection
    C. congestion detection
    D. one way jitter measurements

    03.Which part of the PPPoE server configuration contains the information used to assign an IP
    address to a PPPoE client?

    A. virtual-template interface
    B. DHCP
    C. dialer interface
    D. AAA authentication

    04.What is the two benefits of DHCP snooping? (Choose two.)
    A. prevent static reservation
    B. prevent reservation
    C. prevent DHCP rogue server
    D. track users hosts on the network.

    05.Which RFC was created to alleviate the depletion of IPv4 public addresses?

    A. RFC 4193
    B. RFC 1519
    C. RFC 1518
    D. RFC 1918

    06.Which statement about native VLAN traffic is true?

    A. Cisco Discovery Protocol traffic travels on the native VLAN by default
    B. Traffic on the native VLAN is tagged with 1 by default
    C. Control plane traffic is blocked on the native VLAN.
    D. The native VLAN is typically disabled for security reasons

    07.Where information about untrusted hosts are stored?

    A. CAM table
    B. Trunk table
    C. MAC table
    D. binding database

    plzzzz correct answer….????

Comment pages
Add a Comment