Open In App

Services and Segment structure in TCP

Last Updated : 02 Nov, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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: 
 

  1. Process-to-Process Communication – 
    TCP provides a process to process communication, i.e, the transfer of data that takes place between individual processes executing on end systems. This is done using port numbers or port addresses. Port numbers are 16 bits long that help identify which process is sending or receiving data on a host. 
     
  2. 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 is encapsulated in an IP packet for transmission. The TCP header has information that is required for control purposes which will be discussed along with the segment structure. 
     
  3. Full-duplex service – 
    This means that the communication can take place in both directions at the same time. 
     
  4. Connection-oriented service – 
    Unlike UDP, TCP provides a connection-oriented service. It defines 3 different phases: 
    • Connection establishment
    • Data transfer
    • Connection termination
  5. Reliability – 
    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. 
     
  6. Multiplexing – 
    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. The sequence number of a segment is the byte number of the first byte that is being sent. The acknowledgement number is required since TCP provides full-duplex service. The acknowledgement number is the next byte number that the receiver expects to receive which also provides acknowledgement for receiving the previous bytes. 
Example: 

 

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 – 
A 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, a header is 20 bytes else it can be of upmost 60 bytes. 
Header fields: 
 

  • Source Port Address – 
    A 16-bit field that holds the port address of the application that is sending the data segment. 
     
  • Destination Port Address – 
    A 16-bit field that holds the port address of the application in the host that is receiving the data segment. 
     
  • Sequence Number – 
    A 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 of the segments that are received out of order. 
     
  • Acknowledgement Number – 
    A 32-bit field that holds the acknowledgement number, i.e, the byte number that the receiver expects to receive next. It is an acknowledgement 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 a number of 4-byte words in the header, i.e if the header is 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. 
     
  • Checksum – 
    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. 
     

TCP Connection – 
TCP is connection-oriented. A TCP connection is established by a 3-way handshake.

My Personal Notes arrow_drop_up

Previous Article
Next Article

Similar Reads

TCP Tahoe and TCP Reno
TCP is known as a connection-oriented protocol, which ensures reliability and is also responsible for congestion control mechanisms in the network. TCP Tahoe and TCP Reno are two techniques of TCP congestion control, these are used when the sender receives three duplicate acknowledgments. TCP Tahoe where Tahoe is a lake in the USA. This particular
4 min read
TCP Fast Open and TCP/IP Acceleration
The TCP Fast Open (TFO) and TCP/IP Acceleration are techniques used to improve the performance and efficiency of TCP connections in computer networks. These techniques aim to reduce the latency and improve the throughput of the TCP connections, especially for short-lived connections and web browsing scenarios. TCP Fast Open (TFO): The TCP Fast Open
3 min read
TCP with explicit link failure notification (TCP-ELFN)
TCP with Explicit Link Failure Notification (TCP-ELFN) is an end to end approach used in TCP Ad Hoc wireless networks to improve the performance by decoupling the path break information from congestion information. TCP-ELFN does not depend upon any routing protocols as it requires explicitly only the link failure notification when there is a path f
2 min read
Minimum and Maximum Length of the Header in the TCP Segment and the IP Datagram
The minimum and maximum length of the header in the TCP segment is 20 Bytes and 60 bytes respectively. The minimum and maximum length of the header in the IP datagram are 20 Bytes and 60 Bytes respectively. What is a TCP Header?The below diagram represents the TCP header. Necessary fields for TCP header 4B Source Port Destination Port 4B Sequence N
4 min read
How to calculate Maximum Segment Size in TCP?
Maximum Segment Size refers to size of the largest segment that local host accepts within a single packet. It denotes largest amount of data that host can accept in single TCP segment. For establishing the TCP connection, both sender and receiver indicates Maximum Segment Size they can accept. While transmitting the packets over TCP connection send
3 min read
Wrap Around Concept and TCP Sequence Number
Prerequisite - TCP | Services and Segment structure Transmission Control Protocol (TCP) is one of the most important protocols of the internet protocol. It provides full transport-layer service to applications and generates a virtual circuit between sender and receiver that is active for the duration of the transmission. Its segment consists of a T
6 min read
Difference Between OSI Model and TCP/IP Model
Data communication is a process or act in which we can send or receive data. For data communication two models are available. We will discuss these two models in this article and also see the differences between these two articles. OSI ModelTCP/IP ModelOSI ModelOSI stands for Open Systems Interconnection. It has 7 layers Physical layer, Data Link l
3 min read
TCP and UDP in Transport Layer
Layer 3 or the Network layer uses IP or Internet Protocol which being a connection less protocol treats every packet individually and separately leading to lack of reliability during a transmission. For example, when data is sent from one host to another, each packet may take a different path even if it belongs to the same session. This means the p
4 min read
OSI, TCP/IP and Hybrid Models
OSI Model is developed by International Organization for Standardization or ISO, the Open Systems Interconnection model or OSI model is a critical building block in networking. OSI Model helps in troubleshooting and understanding networks because of the layered approach that it follows. It consists of seven layers in which each layer has its functi
4 min read
Difference between TCP and RTP
1. TCP : TCP is a connection oriented protocol in which the communicating devices establish a connection before transmitting data and close the connection after transmitting the data. 2. RTP : Real-Time Transport Protocol (RTP) is a network protocol which is used for delivering audio and video over networks. RTP is basically used in communication a
1 min read
Article Tags :