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 (42) Comments
Comment pages
1 2 3 4 2834
  1. 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….????

  2. Joe
    January 11th, 2018

    Pls guys what percentage do I need to pass the CCNA exam

  3. Alex
    January 14th, 2018

    Are u planning on writing the exam this month. if so beep me for proper preparation at
    email: {email not allowed}
    Am also planning on writing mine this month

  4. stiven
    January 15th, 2018

    @Alex my
    email: {{email not allowed}}

  5. stiven
    January 15th, 2018

    @Alex my
    email: {{email not allowed}}

  6. stiven
    January 15th, 2018

    @Alex my
    email: stiven.rox At gmail.com

  7. ToMac
    January 18th, 2018

    Passed CCNA Exam today. There were very few questions from the china dump (around 6-10 i guess). 53 total questions. I had to complete around 5 practical tasks, almost all completely new to me ! 2 days ago some of my collegues also passed with ease, because the china dump was 1:1 to the exam. But it seems, it is not anymore…
    So, take care and do not learn dumps only ! It didn’t help me at all

  8. syed
    January 19th, 2018

    @ToMac , How much did you score ?
    And can you send dumps on my mail
    mushaffalanka at gmail dot com

  9. Nuwan
    January 21st, 2018

    I passed the CCNA exam today. I got ACL lab, and 3 simulation task. Altogether 54 Questions. Around 35 Questions from Chinese dump. Yes they are changing the questions now.

  10. Anonymous
    January 22nd, 2018

    Pls , can you send current dumps on my mail: donmereal at gmail dot com.


  11. raymond
    January 23rd, 2018

    please send dumps to me……
    rk31947 @ gmail com (no spaces )

  12. Jeremy
    January 24th, 2018

    please send all current study material and dumps to {email not allowed} thanks!

  13. aliroish
    January 29th, 2018

    dear friends can you send me dump this is may email address: aliroish75at gmaildot com
    Advance thank you

  14. Nav1
    January 29th, 2018

    What is difference between osl layers and tcp

  15. Anonymous
    January 30th, 2018

    dear friends can you send me dump this is may email address: muteka2002ATyahoo.co.uk

  16. manu
    February 5th, 2018

    hi guys can anyone share the latest dump to my ekanjanda 4 @ yahoo .com

  17. Shine
    February 5th, 2018

    Can anyone share the latest dump to this email address:{email not allowed} going to write soon please

  18. anonymous
    February 5th, 2018

    Can anyone share the latest dump @ nethefs1 @ gmail dot com writing soon

  19. OLR4C
    February 6th, 2018

    Can someone please share the latest dump on my email carlobundalian at g mail .com

  20. CCNAFP
    February 7th, 2018

    Hi guys can anyone send me the lates dump on my email ccnafuturepasses at gmal. com! Your effort will be much appreciated!!

  21. PacketTracer
    February 7th, 2018

    Hi guys can anyone send me the lates dump on my email ccnafeaturepasser at gmal. com! Your effort will be much appreciated!!

  22. simon
    February 11th, 2018

    theckjhjepicjNDt78jm,h8YOUM,na879N M,AMAa790olkniu8ajl.31
    621+7hjg7yqdbjjPUUIJ JHCOOMN08ydjkhpdjhuhweyuhuwewiuyigg

  23. Anonymous
    February 11th, 2018

    I have train4sure dumps which i bought in september. Will it be enough if i learn those?. and from where should i learn labs fully.

  24. wajahat
    February 11th, 2018

    I have train4sure dumps which i bought in september. Will it be enough if i learn those?. and from where should i learn labs fully.

  25. CCNA-In-Mexico
    February 12th, 2018

    Where can you get the China dump?

  26. Anonymous
    February 13th, 2018

    Please anyone send me the latest dumps for ccna exam on email: kice_krsteski (at) yahoo . com
    Thanks a lot!!

  27. Aura
    February 14th, 2018

    Can someone send me the latest dumps,please lunguaura90 @ gmail .com

  28. Pascal
    February 16th, 2018

    S’il vous plaît, quelqu’un m’envoie les dernières décharges pour l’examen ccna sur l’email: dattepascal(at)yahoo. Fr
    Merci beaucoup!

  29. Aung
    February 19th, 2018

    Give me dump

  30. James
    February 19th, 2018

    Concepts lay a fundamental foundation here at 9tut. nice job tut.
    Also, guys, if you recently took the CCNA 2001-125 plz email the dumps to jmmyjjkrn at aol dot com

  31. ASAD
    February 23rd, 2018

    someone please send me ccna exam related dumps
    asadsohail12 @ gmail com

  32. Amer
    February 25th, 2018

    someone, please send me the current dumps for ccna

    {email not allowed}

  33. Amer
    February 25th, 2018

    amer7dd @ gmail com

  34. Anonymous
    February 26th, 2018

    Hi! Can anyone send me the latest dumps for CCNA R&S 200-125? Send it here: ngkcnetworkengineer at gmail dot com. Thank you so much!!!

  35. Lizzie
    February 28th, 2018

    Hi, please anyone to send me the latest dumps to {email not allowed}. Thanks.

  36. Lizzie
    February 28th, 2018

    Hi, please anyone to send me the latest dumps to lizdasupa at gmail dot com. Thanks.

  37. hazel
    February 28th, 2018

    kindly send me the updated dumps hazelor13 at gmail dot com. thanks<3

  38. Das
    March 1st, 2018

    Hi friends,
    I am going to write the CCNA exam can you please send m the dump shankda at gmail dot com

    Thanks in advance for your help

  39. Fawad
    March 7th, 2018

    Need the latest dumps for CCNA routing and switching. I am studying from a couple of websites but need the dumps for more help. Thanks. Please send at qureshi313blog at gmail dot com.

  40. Matrix
    March 8th, 2018

    Hello guys.
    Am studying for my CCNA exam for next week.
    Please update me with the latest dump.
    I will surely appreciate.
    Send to psyriamo05 at gmail or yahoo thanks

  41. Anonymous
    March 15th, 2018

    Hello everyone.

    I am studying for the CCENT and need the latest dump. Can someone please send that to me? nborden333 at gmail.com

  42. kiran adhikari
    March 15th, 2018

    can you help me someone by sending latest dump,my email is {email not allowed}

Comment pages
1 2 3 4 2834
Add a Comment