The Transmission Control Protocol is the most common transport layer protocol. It works together with IP and provides a reliable transport service between processes using the network layer service provided by the IP protocol.
The various services provided by the TCP to the application layer are as follows:
Process-to-Process Communication –
TCP provides process to process communication, i.e, the transfer of data takes place between individual processes executing on end systems. This is done using port numbers or port addresses. Port numbers are 16 bit long that help identify which process is sending or receiving data on a host.
Stream oriented –
This means that the data is sent and received as a stream of bytes(unlike UDP or IP that divides the bits into datagrams or packets). However, the network layer, that provides service for the TCP, sends packets of information not streams of bytes. Hence, TCP groups a number of bytes together into a segment and adds a header to each of these segments and then delivers these segments to the network layer. At the network layer, each of these segments are encapsulated in an IP packet for transmission. The TCP header has information that is required for control purpose which will be discussed along with the segment structure.
Full duplex service –
This means that the communication can take place in both directions at the same time.
Connection oriented service –
Unlike UDP, TCP provides connection oriented service. It defines 3 different phases:
- Connection establishment
- Data transfer
- Connection termination
(IMP: This is a virtual connection, not a physical connection, means during the transmission the resources will not be reserved and the segments will not follow the same path to reach the destination but it is a connection orientation in the sense that segments will arrive in order by the help of sequence number.)
TCP is reliable as it uses checksum for error detection, attempts to recover lost or corrupted packets by re-transmission, acknowledgement policy and timers. It uses features like byte number and sequence number and acknowledgement number so as to ensure reliability. Also, it uses congestion control mechanisms.
TCP does multiplexing and de-multiplexing at the sender and receiver ends respectively as a number of logical connections can be established between port numbers over a physical connection.
Byte number, Sequence number and Acknowledgement number:
All the data bytes that are to be transmitted are numbered and the beginning of this numbering is arbitrary. Sequence numbers are given to the segments so as to reassemble the bytes at the receiver end even if they arrive in a different order. Sequence number of a segment is the byte number of the first byte that is being sent. Acknowledgement number is required since TCP provides full duplex service. Acknowledgement number is the next byte number that the receiver expects to receive which also provides acknowledgement for receiving the previous bytes.
In this example we see that, A sends acknowledgement number1001, which means that it has received data bytes till byte number 1000 and expects to receive 1001 next, hence B next sends data bytes starting from 1001. Similarly, since B has received data bytes till byte number 13001 after the first data transfer from A to B, therefore B sends acknowledgement number 13002, the byte number that it expects to receive from A next.
TCP Segment structure –
TCP segment consists of data bytes to be sent and a header that is added to the data by TCP as shown:
The header of a TCP segment can range from 20-60 bytes. 40 bytes are for options. If there are no options, header is of 20 bytes else it can be of upmost 60 bytes.
Source Port Address –
16 bit field that holds the port address of the application that is sending the data segment.
Destination Port Address –
16 bit field that holds the port address of the application in the host that is receiving the data segment.
Sequence Number –
32 bit field that holds the sequence number, i.e, the byte number of the first byte that is sent in that particular segment. It is used to reassemble the message at the receiving end if the segments are received out of order.
Acknowledgement Number –
32 bit field that holds the acknowledgement number, i.e, the byte number that the receiver expects to receive next. It is an acknowledgment for the previous bytes being received successfully.
Header Length (HLEN) –
This is a 4 bit field that indicates the length of the TCP header by number of 4-byte words in the header, i.e, if the header is of 20 bytes(min length of TCP header), then this field will hold 5 (because 5 x 4 = 20) and the maximum length: 60 bytes, then it’ll hold the value 15(because 15 x 4 = 60). Hence, the value of this field is always between 5 and 15.
Control flags –
These are 6 1-bit control bits that control connection establishment, connection termination, connection abortion, flow control, mode of transfer etc. Their function is:
- URG: Urgent pointer is valid
- ACK: Acknowledgement number is valid( used in case of cumulative acknowledgement)
- PSH: Request for push
- RST: Reset the connection
- SYN: Synchronize sequence numbers
- FIN: Terminate the connection
Window size –
This field tells the window size of the sending TCP in bytes.
This field holds the checksum for error control. It is mandatory in TCP as opposed to UDP.
Urgent pointer –
This field (valid only if the URG control flag is set) is used to point to data that is urgently required that needs to reach the receiving process at the earliest. The value of this field is added to the sequence number to get the byte number of the last urgent byte.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- TCP with explicit link failure notification (TCP-ELFN)
- Why does DNS use UDP and not TCP?
- Differences between TCP and UDP
- TCP and UDP server using select
- Wrap Around Concept and TCP Sequence Number
- TCP and UDP in Transport Layer
- OSI, TCP/IP and Hybrid models
- Difference between TCP and RTP
- TCP/IP Ports and Its Applications
- Various TCP and UDP ports
- Difference between SCTP and TCP
- Error Control in TCP
- TCP/IP Model
- TCP 3-Way Handshake Process
- TCP Connection Termination
- TCP Congestion Control
- TCP Server-Client implementation in C
- TCP Connection Establishment
- TCP flags
- Devices used in each layer of TCP/IP model
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.