A TCP segment consists of a TCP header, TCP options and the data that the segment transports. Following table represents a TCP header and it’s fields. The fields of TCP header are source port and destination port of a application, 32 bit sequence number, 32 bit acknowledgement number, TCP header length, 6 reserved bits, 6 flags (URG, ACK, PSH, RST, SYS, FIN), 16 bit window size, 16 bit TCP checksum, 16 bit urgent pointer, Options if any and padding if needed. Minimum header length is 20 bytes long i.e 5 32 bit words. The TCP maximum header size can be up to 15, 32 bit words. i.e. 60 byte long.
|0||16-bit source port||16-bit destination port|
|32||32-bit sequence number|
|64||32-bit acknowledgement number|
|96||Header Length 4-bits||Reserved 6-bits||URG||ACK||PSH||RST||SYN||FIN||16-bit window size|
|128||16-bit TCP checksum||16-bit urgent pointer|
Source and Destination Ports:
Both source and destination ports are 16-bit fields identify protocol ports of the sending and receiving applications. The source and destination port numbers plus source and destination IP addresses in the IP header combine to uniquely identify each TCP connection referred as a socket.
Sequence number is a 32-bit wide field identifies the first byte of data in the data area of the TCP segment. We can identify every byte in a data stream by a sequence number.
Acknowledge number is also a 32-bit wide field which identifies the next byte of data that the connection expects to receive from the data stream.
Header length is a field which consists of 4 bit to specifies the length of the TCP header in 32-bit words. Receiving TCP module can calculate the start of the data area by examining the header length field.
URG – URG flag tells the receiving TCP module as it is urgent data
ACK – ACK tells the receiving TCP module that the acknowledge number field contains a valid acknowledgement number
PSH – PSH flag tells the receiving TCP module to immediately send data to the destination application
RST – RST flag asks the receiving TCP module to reset the TCP connection
SYN – SYN flag tells the receiving TCP module to synchronize sequence number
FIN – FIN flag tells the receiving TCP module that the sender has finished sending data
Window size field is a 16-bit wide which tells the receiving TCP module the number of bytes that the sending end id willing to accept. The value in this field specifies the width of the sliding window.
TCP checksum is a 16-bit wide filed includes the TCP data in it’s calculations. This field helps the receiving TCP module to detect data corruption. That is, TCP requires the sending TCP module to calculate and include checksums in this field and receiving TCP module to verify checksums when they receive data. The data corruption is detected in this way.
Urgent pointer is a 16-bit wide field specifies a byte location in the TCP data area. It points to the last byte of urgent data in the TCP data area.
TCP header includes an optional options field like the IP header. During the initial negotiations between two ends of a TCP connection, this field is used with maximum segment size option, which advertise the largest segment that the TCP module expects to receive.