The TCP Three-Way Handshake Explained   - Codecademy Blog (2024)

The Transmission Control Protocol/Internet Protocol (TCP/IP) is the most widely used internet connectivity protocol for enabling communication of data between computers across a computer network.

TCP/IP, paired with Hypertext Transfer Protocol (HTTP), has revolutionized the way we do everyday things, allowing for information to be passed nearly instantaneously around the world. The internet as we know it (mostly in web browsers) is possible via the network connection created by something called the TCP three-way handshake. We go over how it all works in-depth in our free course Introduction to IT, but here’s an overview of the basics (which you’ll need to know if you want to get into web development).

Learn something new for free

  • Intro to ChatGPT
  • Learn SQL

Layers of TCP/IP

The TCP/IP model is a four-layer protocol stack supporting computer networking and connections. It is an internet protocol that standardizes how data is processed, transmitted, and received.

The model is divided into the following layers, each performing specific duties:

  • Application layer: Interacts with software applications, allocates resources, and synchronizes communication.
  • Transport layer: Transports data from the source to the receiver (and back, if necessary) and ensures the correct sequence of transmissions.
  • Internet layer: Routes data packets between the different addresses on a computer network.
  • Network Access layer: Explains how data should be transmitted throughout the network.

The Transport layer is an interface for network applications that allows for error checking, flow control, and verification of communications. Data from an application program interface (at the Application layer) passes to the Transport layer and then to the Transmission Control Protocol (TCP). The protocol creates the connection between a client and server via the three-way handshake.

  • A client is a computer requesting services from another computer on a network.
  • A server is a computer offering services to other computers on a network.

TCP Segments

The Transmission Control Protocol (TCP) is a reliable connection-oriented protocol. A connection-oriented protocol begins, maintains/monitors, and ends a connection between two computers.

TCP processes data via Stream-oriented Processing, which means that it accepts a byte of data at a time and formats it into segments. A segment is a data package encapsulating the entire Application layer message. If the data message arrives out of order, TCP can resequence the data to restore to the original order.

A TCP connection is full-duplex, meaning data can flow independently in each direction (from client to server). The sending machine records status information to ensure delivery. Every data package sent across the network receives an acknowledgment from the receiving computer. A data segment is formatted into 13 distinct parts, as illustrated below.

Source Port (16-bit)Port number of the application on the sending machine
Destination Port (16-bit)Port number of the application on the receiving machine
Sequence Number (32-bit)The byte number of the first byte of data in the TCP packet sent
Acknowledgment Number (32-bit)Acknowledges a received segment – the value +1 of the number the receiving computer expects to receive.
Data Offset (4-bit)Tells receiving machine where the data begins
Reserved (6-bit)Reserved for future development
Control flags (1-bit each)URGUrgent pointer fieldACKAcknowledgmentPSHPush all data to the receiving applicationRSTReset connectionSYNSynchronization request (used to open a connection)FINA sending computer has no more data to transmit (used to close connection)
Window (16-bit)The range of sequence numbers beyond the last acknowledged sequence number that the sending machine can transmit without further acknowledgment. (control flow)
Checksum (16-bit)Checks for corruption in the datagram
Urgent Pointer (16-bit)Urgent information point in sequence number
OptionsOptional settings
PaddingEnsures 32-bit boundary
DataAdditional data being transmitted with the segment

What is a TCP three-way handshake?

A TCP connection is a graceful connection-oriented protocol to establish, maintain/monitor, and terminate network connections reliably between two computers. It’s accomplished by a sequence/acknowledgment system where the client and server synchronize their sequence numbers. A network connection is made between client and server in three steps (a.k.a. handshakes).

Establishing a connection

Step 1

The client sends a segment to the server that includes:

  • A SYN number to open the connection.
  • An ACK number with information acknowledging a connection.
  • The client’s ISN (initial sequence number).

The SYN is a synchronization request, and the ACK states the current value of the acknowledgment sequence. If a connection is being made for the first time, then ACK starts at 0.

Step 2

The server receives the client’s segment. In response, the server acknowledges the client’s ISN by sending back an ACK with 1 added to its value. Additionally, a SYN request is sent from the server, along with its own ISN, back to the client.

Step 3

The client receives the server’s request for synchronization and responds with a segment that contains an ACK to acknowledge receipt of the server’s ISN, and the connection is established.

Connection

Once the TCP three-way handshake is made, the data segment is then passed to the Internet layer. At this layer, IP provides logical-addressing info, encloses data into a datagram, and provides routing to support delivery across the interconnected network. Finally, at the Network Access layer, which provides an interface, a datagram is received and formatted into a frame. The frame is then converted into a bitstream that is transmitted over the network.

Terminating a connection

Step 1

The client sends a segment containing a FIN value set to 1. The client application then enters fin-wait state, which allows it to continue to receive and process segments in the queue. However, no additional data is transmitted.

Step 2

Then, the server sends ACK back to the client, which acknowledges receipt of the FIN, and sends any remaining segments.

Step 3

The server notifies the local application that a FIN segment has been received and then transmits FIN to the client, signaling the connection’s close.

Step 4

Once received, the client sends ACK to the server, acknowledging receipt of FIN, and gracefully closing the connection.

In the context of the Web, the “clients” are web browsers that connect to web servers and present data in a predetermined format. The web server communicates using HTTP. After a TCP connection is made, the browser uses HTTP commands to request a web page URL, which ultimately results in what we see on the screen made with HTML/CSS and JavaScript.

Want to learn more about how the web works? Check out our web development and IT courses for more info.

Related courses

5 courses

Intro to ChatGPT Beginner Learn about ChatGPT, one of the most advanced AI systems available today, and dive into the world of Generative AI.
Learn SQL Beginner In this SQL course, you’ll learn how to manage large datasets and analyze real data using the standard data management language.
Learn to Code with Blockly Beginner Want to learn how to get started with programming in an interactive way? Try our drag and drop code lessons!
Choosing a Programming Language Beginner This course will introduce learners to factors to consider when picking a first language as well as describe some popular options.
Choosing a Career in Tech Beginner Are you feeling confused about where to aim for with your career goals? Take this course to learn about different career options!

Subscribe for news, tips, and more

The TCP Three-Way Handshake Explained   - Codecademy Blog (2024)

FAQs

How does a 3-way handshake work in TCP? ›

The TCP handshake

TCP uses a three-way handshake to establish a reliable connection. The connection is full duplex, and both sides synchronize (SYN) and acknowledge (ACK) each other. The exchange of these four flags is performed in three steps—SYN, SYN-ACK, and ACK—as shown in Figure 3.8.

Does HTTP use three-way handshake? ›

Both HTTP GET and HTTP POSTS use TCP. If you are asking whether a POST also requires a 3-way TCP handshake (syn-synack-ack), it does just like any other TCP connection. The TCP handshake is required before any application protocol (such as HTTP) starts work.

What is the correct order of messages sent in a TCP handshake? ›

TCP 3-Way Handshake Process
  • The client starts the process and sets the SYN flag to 1. The client sends the message to the server by setting the SYN flag to 1. ...
  • The server replies with (SYN+ACK) ...
  • The final acknowledgment from the client (ACK)

What happens after a TCP 3-way handshake? ›

With the completion of the three-way handshake, both devices have exchanged initial sequence numbers, synchronized their communication settings, and established a reliable connection. Subsequent data transmission can now occur between the client and server using the agreed-upon sequence numbers and other parameters.

What is the mechanism of handshaking? ›

A handshake is a means of synchronization among communicating mechanisms. In its simplest form it involves two mechanisms connected by a pair of so-called links, one for sending signals and one for receiving signals.

Does UDP use a three-way handshake? ›

User datagram protocol (UDP) operates on top of the Internet Protocol (IP) to transmit datagrams over a network. UDP does not require the source and destination to establish a three-way handshake before transmission takes place. Additionally, there is no need for an end-to-end connection.

What is the first step of TCP's three-way handshake process? ›

How the TCP three-way handshake works. Step 1: The client uses the IP address of the server to request an initial connection. This message is known as a SYN, which stands for synchronization. Step 2: The server can then choose to allow the connection and allocate resources such as a network port.

How TCP terminates the connection? ›

The TCP Connection Termination Process

Initiation of Termination: The party wishing to terminate the connection sends a TCP segment with the FIN (Finish) flag set to the other party. The FIN flag indicates that the sender has no more data to send.

What are the three steps and order of the TCP three-way handshake process? ›

Steps of a three-way handshake

TCP is responsible for ensuring data is delivered correctly between computers on an internet network. The three-way handshake involves the following three steps: synchronize (SYN), synchronize-acknowledge (SYN-ACK), and acknowledge (ACK).

How exactly does TCP work? ›

Transmission Control Protocol (TCP) is a communications standard that enables application programs and computing devices to exchange messages over a network. It is designed to send packets across the internet and ensure the successful delivery of data and messages over networks.

What are the three basic operations of the TCP? ›

The three phases of TCP operations
  • Connection establishment.
  • Data transfer.
  • Connection termination.
Dec 22, 2020

Is TCP or UDP a three-way handshake? ›

TCP is connection-oriented while UDP is connectionless

The connection is established via a three-way handshake. The client sends a synchronization request, the server sends back an acknowledgment, and the client returns a synchronization acknowledgment in response. Comparatively, UDP is a connectionless protocol.

How does TCP FIN work? ›

The TCP FIN flag is used to terminate a TCP connection by signaling the end of data transmission to the remote endpoint. The sender sends a FIN segment, which indicates that it has no more data to send and requests to close the connection.

Which field in the TCP header indicates the status of the three-way handshake process? ›

Expert-Verified Answer. The field in the TCP header that indicates the status of the three-way handshake process is the Flags field. The Flags field is 6 bits long and is used to control various aspects of the TCP connection. Within the Flags field, there are several individual bits that have specific meanings.

What is a three-way handshake in TCP quizlet? ›

A three-way-handshake is a method used in a TCP/IP network to create a connection between a local host/client and server. It is a three-step method that requires both the client and server to exchange SYN and ACK (acknowledgment) packets before actual data communication begins.

Top Articles
SIP Tax Benefit - How To Start SIP To Save Tax in 2024
Add and remove a product key
Katie Pavlich Bikini Photos
Gamevault Agent
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
Things To Do In Atlanta Tomorrow Night
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Dmv In Anoka
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Rogold Extension
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Weekly Math Review Q4 3
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Free Carnival-themed Google Slides & PowerPoint templates
Otter Bustr
Selly Medaline
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated:

Views: 5904

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.