Home > TCP and UDP Tutorial

TCP and UDP Tutorial

September 20th, 2016 Go to comments

TCP Features

Some popular TCP features we will learn here are: Multiplexing using port numbers, Flow control using windowing and Reliability (Error Detection and Error recovery)

Multiplexing using port numbers

Suppose you are using a laptop for web browsing, email communicating and FTP uploading at the same time. All of them require using TCP while your laptop only has one IP address (with one network card) so how your laptop knows which packets received from the Internet are dedicated for which application?

Above question is solved with port numbers. Each application will use a different and available port number to communicate with outside world. For example your laptop can choose port 50000 for web browsing, port 50001 for email communicating and port 50002 for FTP uploading.


Notice that your laptop can choose any available source port but it must use pre-defined destination ports for well-known services. Port numbers are defined in three ranges:
+ Well-known port numbers (0 through 1023): assigned to key or core services that systems offer
+ Registered port numbers (1024 through 49151): assigned to industry applications and processes. For example: 1433 is assigned for Microsoft SQL Server process)
+ Dynamic port numbers (49152 through 65535): used as temporary ports for specific communications. Our laptop can use these ports for communication

The table below lists TCP ports for well-known services:

TCP Service Description Port
FTP File Transfer Protocol 20, 21
SSH Secure shell 22
Telnet Terminal network 23
SMTP Simple Mail Transfer Protocol 25
DNS Domain Name Server 53
HTTP Hyper Text Transfer Protocol 80
HTTPS Hyper Text Transfer Protocol Secure 443

Note: There are some other well-known ports that are not listed here. The well-known ports are assigned by the Internet Assigned Numbers Authority (IANA) in the range of 0 to 1023.

Multiplexing relies on a concept called a socket. A socket consists of three things:

+ An IP address
+ A transport protocol
+ A port number

So suppose the IP address on our laptop is and use TCP to access web server with port 50000, we may write the socket (, TCP, 50000). For web server application running on the Web Server with IP the socket should be (, TCP, 80) as the web server uses the well-known port 80 for HTTP.

The socket on each computer is unique so the connection between two sockets on two computers identify a unique connection between them. Therefore you can use multiple applications on the same computer at the same time. Each application will use a unique source port so they cannot interfere with each other.

We only mentioned about source ports but notice TCP header requires both source port and destination port. That means if our laptop wants to connect to a Web Server it must include the destination port in TCP header as well. The destination port for Web Server in this case is 80. When the Web Server replies to our laptop, it uses the laptop’s source port as its destination port (50000 in this case).



Note: Both TCP and UDP use multiplexing with port numbers for their services.

Flow-control using windowing

In the TCP header there is a field called “Window” which plays an important role in the TCP transmission. A “Window” specifies the number of segments the sender can forward without receiving an acknowledgment. It is the key to transfer data and flow control efficiently. Let’s see how it works!

After the TCP connection has been established, both the client and server use this Window field to tell the other how many bytes of data it is willing to receive at one time before sending an acknowledgement to the sender. The larger the window size number (in bytes), the greater the amount of data that the host can transmit. For example, with a Window size of 1 (byte), every one byte must be acknowledged before sending the next one.


But waiting for ACK after each segment would be very inefficient. So TCP tries to increase the Window size to 3 (bytes), which means every three bytes can be received before sending the acknowledgement.


As you can see, the bigger the Window size, the fewer ACKs needed to be sent and the more efficient the transmission is. So the receiver will try to increase the Window size after each successful transmission so that the sender can send more. But the Window size cannot increase forever, TCP stops increasing the Window size when the receiver does not send an ACK (within a specific time period) or when the Window size reaches its maximum value. If a congestion occurs on the link then TCP may decrease the Window size.

The window size is variable during the lifetime of a connection so we often refer it as a “sliding window”.

If the sender does not receive the ACK in time, it knows that the segments should be resent, and that the transmission rate should be slowed down. Suppose Host A did not receive the expecting ACK 7 then it knows segments 4, 5, 6 should be resent.


Reliability (Error Detection and Error recovery)

This is the most important feature of TCP. TCP must recover from data that is damaged, lost, duplicated during the transmission. But please grasp the difference between error detection and error recovery first:
+ Error detection: the detection of errors during the transmission. Error detection does not repair corrupted data, it just detects it
+ Error recovery: the detection of errors and repair them

To achieve error detection, TCP adds some extra bits to the data, called checksum. A TCP sender computes the checksum value based on the contents of the TCP header and data fields. This 16-bit value will be compared with the value the receiver generates using the same computation. If the values match, the receiver can believe that segment arrived intact. If the values do not match, the receiver indicates an error occurred and the segment is discarded and a notification will be sent to the receiver depending on how the TCP stack is implemented on the receiver’s operating system.

To achieve error recovery, TCP uses the Sequence number (at the sender’s side) and Acknowledgement fields (at the receiver’s side) in the TCP header. These two fields are also used to find out lost, duplicated segments. Let’s see an example.

In the transmission below, host A sends three segments 1, 2, 3 to host B. Segment 2 was lost while segment 3 arrived to Host B. Then Host B replied with an ACK 2, implying that it is expecting segment 2 next. Host A can re-send another segment 2 to recover the lost segment. If Host B receive that segment it will ask for the segment 4 (because it already has segment 3).

TCP_Error_Recovery.jpgError recovery

You may ask “what will happen if the ACK 2 sent from Host B is also lost?” In fact, after sending each segment Host A sets a retransmission timer, just in case the ACK is lost (or all the sending segments are lost; Host B would not send ACK in this case because it did not receive anything). If this timer expires, Host A will send all the segments again.

Note: UDP does support error detection (via checksum) but it does not support error recovery. If UDP finds a corrupted segment, it just simply drop it.

Let’s sum up all things we learned about TCP and UDP so far.


+ Both TCP and UDP operate at Transport Layer
+ Both TCP and UDP use Multiplexing via port numbers


Reliable Unreliable
Connection-oriented Connectionless
Segment retransmission and flow control through windowing No retransmission or windowing
Segment sequence No sequencing
Acknowledge segment No acknowledgement
Start and end the communication by three-way handshake and four-way termination No action is required before and after sending real data

Finally we show the TCP and UDP header in detail for your reference. There are some fields which are out of scope of this tutorial.

tcp_header.jpgTCP Header (20 bytes)

Notice about the FLAG fields (between the “Reserved” and “Window Size” fields). If SYN bit is turned on, it is a SYN message. If ACK bit is turned on, it is an ACK message. If both SYN and ACK bits are turned on, it is a SYN-ACK message.

And this is the UDP header:

UDP_header.jpgUDP Header (8 bytes)

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