Uploaded November 2016 | Updated November 2026, 3 hours ago
3 way handshake. Networking & TCP/IP Tutorial. TCP/IP Explained
TRANSCRIPT:
We dive into the TCP three-way handshake.
Most folks can tell you that the three-way handshake is Syn, Syn-Ack, Ack. What does that mean? In this video I’give you all the nitty-gritty details so that you will understand everything you need to know about three-way handshake. Why is it important to understand the three-way handshake? Because it’s really the basis of understanding TCP itself.
At the most basic level what is it the three-way handshake does? It establishes a connection between a client & a server. So when they say that TCP is connection oriented, it is the three-way handshake that creates the connection in the first place. Remember that UDP is not connection oriented so therefore it does not use the three-way handshake
Three-way handshake actually performs 4 specific functions for the TCP. These functions, in no particular order, are:
• is the destination port listening?
• Advertisement of ephemeral ports
• advertisement of ISN’s
• advertisement of window sizes
So in this video is go over in detail each of the 4 functions above and then I’ll do a live demonstration of the three-way handshake in Wireshark.
Let’s start with 1st function of the three-way handshake:
• Is the destination port listening?
In TCP, we have a client host that tries to connect to a server host.
The client always sends the first packet, which is a SYN. If the server is listening on the destination port of the SYN packet, then it will respond with the SYN ACK packet.
If the server is not listening, i.e. the server port is closed, then then it will not respond with SYN ACK and the connection process terminates here.
We go to the next function of the three-way handshake which is:
• Advertisement of ephemeral ports
While IP address tells TCP/IP what host to go to, the port number says where on the host to go to, specifically what application to go to.
There are 2 different types of ports: well-known ports and ephemeral ports.
Examples of well-known ports: port 80 for HTTP, port 443 for HTTPs, & port 23 for Telnet.
If the client wants to connect to a specific Web server, the first packet of the three-way handshake will show a destination port of port 80 & a source port of some random number greater than 1023, such as 12345.
12345 is chosen at random by the client and is called an ephemeral port. The server must be aware of this ephemeral port number to allow it to communicate back to the correct application process on the client
We go to the next function of the three-way handshake which is:
• Advertisement of ISN’s
ISN stands for Initial Sequence Number.
But before we can understand what an initial sequence number is, we need to understand concept of sequence numbers in general.
TCP numbers all data bytes that are transmitted during a connection, and TCP keeps track of the sequence number to maintains its reliability.
However the first sequence number is called an ISN and is randomly generated for security purposes. If security were not a concern, we could simply start counting sequence numbers at zero, in which case this function of the TCP handshake might not be necessary.
So TCP begins counting bytes from the ISN and not zero. To be clear, the sequence number refers to the byte number and not the segment or packet number.
Supposing the ISN were 1147, and the total data to be sent was 5000 bytes, then the bytes would be numbered from 1147 to 6147
Specifically the sequence number for each segment is the number of the first byte of data carried by that segment.
Now working hand-in-hand with the sequence number is an acknowledgment number.
This is used by TCP to acknowledge that it has received data.
Specifically the acknowledgment number defines the number of the next bite that TCP expects to receive.
Note that the acknowledgment is cumulative. This means that TCP takes the number of the last bite that it received, adds one to it then advertises this sum as the acknowledgment number.
With these concepts in mind, this is how the three-way handshake goes:
Segment [1]
the client sends a segment to the server with the SYN flag set. The client generates an ISN at random, and sends it to the server.
Segment[2]
the server responds with the SYN and ACK flags set.
This segment has 2 functions:
1st function is the SYN for communication the other direction. The server uses this segment to initialize the sequence number for numbering the bytes sent from the server to the client.
2nd function is to acknowledge the receipt of the segment from the client, by setting the ACK flag, and generating an acknowledgment number which is the next sequence number it expects to receive from the client.
Check out more of my great TCP/IP & Cyber Security Tutorials:
youtube.com/playlist?list=PLjXnMD3emuh1QYexMGYGvr_aM0KTnCXFU
…
3 way handshake. Networking & TCP/IP Tutorial. TCP/IP Explained
TRANSCRIPT:
We dive into the TCP three-way handshake.
Most folks can tell you that the three-way handshake is Syn, Syn-Ack, Ack. What does that mean? In this video I’give you all the nitty-gritty details so that you will understand everything you need to know about three-way handshake. Why is it important to understand the three-way handshake? Because it’s really the basis of understanding TCP itself.
At the most basic level what is it the three-way handshake does? It establishes a connection between a client & a server. So when they say that TCP is connection oriented, it is the three-way handshake that creates the connection in the first place. Remember that UDP is not connection oriented so therefore it does not use the three-way handshake
Three-way handshake actually performs 4 specific functions for the TCP. These functions, in no particular order, are:
• is the destination port listening?
• Advertisement of ephemeral ports
• advertisement of ISN’s
• advertisement of window sizes
So in this video is go over in detail each of the 4 functions above and then I’ll do a live demonstration of the three-way handshake in Wireshark.
Let’s start with 1st function of the three-way handshake:
• Is the destination port listening?
In TCP, we have a client host that tries to connect to a server host.
The client always sends the first packet, which is a SYN. If the server is listening on the destination port of the SYN packet, then it will respond with the SYN ACK packet.
If the server is not listening, i.e. the server port is closed, then then it will not respond with SYN ACK and the connection process terminates here.
We go to the next function of the three-way handshake which is:
• Advertisement of ephemeral ports
While IP address tells TCP/IP what host to go to, the port number says where on the host to go to, specifically what application to go to.
There are 2 different types of ports: well-known ports and ephemeral ports.
Examples of well-known ports: port 80 for HTTP, port 443 for HTTPs, & port 23 for Telnet.
If the client wants to connect to a specific Web server, the first packet of the three-way handshake will show a destination port of port 80 & a source port of some random number greater than 1023, such as 12345.
12345 is chosen at random by the client and is called an ephemeral port. The server must be aware of this ephemeral port number to allow it to communicate back to the correct application process on the client
We go to the next function of the three-way handshake which is:
• Advertisement of ISN’s
ISN stands for Initial Sequence Number.
But before we can understand what an initial sequence number is, we need to understand concept of sequence numbers in general.
TCP numbers all data bytes that are transmitted during a connection, and TCP keeps track of the sequence number to maintains its reliability.
However the first sequence number is called an ISN and is randomly generated for security purposes. If security were not a concern, we could simply start counting sequence numbers at zero, in which case this function of the TCP handshake might not be necessary.
So TCP begins counting bytes from the ISN and not zero. To be clear, the sequence number refers to the byte number and not the segment or packet number.
Supposing the ISN were 1147, and the total data to be sent was 5000 bytes, then the bytes would be numbered from 1147 to 6147
Specifically the sequence number for each segment is the number of the first byte of data carried by that segment.
Now working hand-in-hand with the sequence number is an acknowledgment number.
This is used by TCP to acknowledge that it has received data.
Specifically the acknowledgment number defines the number of the next bite that TCP expects to receive.
Note that the acknowledgment is cumulative. This means that TCP takes the number of the last bite that it received, adds one to it then advertises this sum as the acknowledgment number.
With these concepts in mind, this is how the three-way handshake goes:
Segment [1]
the client sends a segment to the server with the SYN flag set. The client generates an ISN at random, and sends it to the server.
Segment[2]
the server responds with the SYN and ACK flags set.
This segment has 2 functions:
1st function is the SYN for communication the other direction. The server uses this segment to initialize the sequence number for numbering the bytes sent from the server to the client.
2nd function is to acknowledge the receipt of the segment from the client, by setting the ACK flag, and generating an acknowledgment number which is the next sequence number it expects to receive from the client.
Check out more of my great TCP/IP & Cyber Security Tutorials:
youtube.com/playlist?list=PLjXnMD3emuh1QYexMGYGvr_aM0KTnCXFU
…










