TCP - Transport Layer Protocol
TCP (Transmission Control Protocol) is a connection-oriented transport layer protocol that ensures reliable, ordered, and error-checked delivery of data between applications over a network.
Category |
Description |
Use Case |
---|---|---|
Connection Oriented |
TCP establishes a reliable, connection-oriented communication channel using a three-way handshake before data exchange begins. |
Web browsing, file transfers, and remote login |
Reliable Data Transfer |
Ensures complete and accurate delivery of data using acknowledgments, retransmissions, and sequencing. |
Email, file sharing, database transactions |
Error Detection |
Uses checksums to detect corruption in headers and payloads during transmission. |
Reliable communication in noisy or error-prone networks |
Flow Control |
Uses a sliding window mechanism to match sender rate with receiver capability, avoiding overwhelming the receiver. |
Prevent buffer overflow in receiving systems |
Port Addressing |
Identifies sending and receiving applications using 16-bit source and destination ports. |
Supports multiple simultaneous networked applications |
Graceful Connection Termination |
Uses a four-step FIN/ACK process to properly close a connection and release resources on both sides. |
Ensures clean session closure without data loss |
Congestion Control |
Dynamically adjusts sending rate based on perceived network congestion using algorithms like AIMD. |
Stabilizes network load and prevents congestion collapse |
Stream Oriented |
Treats transmitted data as a continuous stream of bytes rather than discrete packets. |
Ideal for long-lived, persistent connections like SSH or HTTP |
Ordered Delivery |
Guarantees data is delivered in the exact sequence it was sent by reordering out-of-order segments. |
Application-level data consistency and correctness |
Header |
Describes fields in the TCP header such as sequence number, ACK number, window size, flags, and checksum. |
Packet inspection, firewall rules, and protocol analysis |
Header Options |
TCP headers may include optional fields like MSS, Window Scale, Timestamps, and SACK for enhanced performance. |
Improve performance and compatibility in diverse environments |
Common Level Options |
Common configuration options include timeout settings, keepalive, and Nagle’s algorithm. |
Customizing TCP behavior for specific applications |
Socket Level Options |
OS-level socket APIs allow control over TCP behavior via options like SO_REUSEADDR, TCP_NODELAY, etc. |
Fine-tune networking behavior in applications |
Linux Settings |
System-wide TCP behavior can be configured in Linux via /proc/sys/net/ipv4/tcp_* settings. |
Performance tuning and security hardening in Linux systems |
RFC: RFC 793 (TCP Specification)
Main Features:
Establishes a reliable connection using a three-way handshake (SYN, SYN-ACK, ACK)
Operates at OSI Layer 4 (Transport Layer)
Guarantees ordered, lossless, and duplicate-free data delivery
Maintains session state throughout the communication
Supports full-duplex communication
Gracefully terminates connection using a four-way FIN handshake
Use Cases:
Reliable data transfer in web applications (HTTP/HTTPS)
File transfers (FTP, SFTP)
Remote sessions (SSH, Telnet)
Email protocols (SMTP, IMAP, POP3)
Alternative Protocols:
UDP – Connectionless transport protocol (less overhead)
SCTP – Message-oriented, reliable protocol (used in telecom)
QUIC – Modern alternative using UDP with TCP-like reliability
Let us learn more about Connection-Oriented TCP:
RFC: RFC 793 (Core TCP Reliability Features)
Main Features:
Ensures error-free, ordered, and complete data delivery
Uses acknowledgments (ACKs) and sequence numbers to track data
Automatically retransmits lost or corrupted packets
Implements sliding window for efficient transmission
Detects and avoids duplicate data at the receiver
Guarantees delivery through timeout and retry mechanisms
Use Cases:
Downloading files (FTP, HTTP, HTTPS)
Email services (IMAP, POP3, SMTP)
Database synchronization
Remote access tools (SSH, Telnet)
Alternative Protocols:
UDP – Fast but unreliable, no retransmissions or guarantees
QUIC – Uses UDP but adds reliability and congestion control
SCTP – Alternative transport with built-in reliability for messages
Let us learn more about Reliable Data Transfer in TCP:
RFC: RFC 793 (TCP Protocol Specification)
Main Features:
Uses a 16-bit checksum field in the TCP header to detect data corruption
Verifies the entire TCP segment, including header and payload
Protects against accidental errors introduced during transmission
Receiver discards packets with checksum mismatches
Works with IPv4 and IPv6 pseudo-headers for end-to-end verification
Use Cases:
Ensuring data integrity over unreliable networks
Detecting corruption in transmitted files or web content
Verifying segment correctness in email, SSH, or VoIP streams
Supporting high-integrity transactions in financial systems
Alternative Protocols:
UDP – Optional checksum, no guaranteed error detection
SCTP – Stronger CRC-based error detection
QUIC – Relies on cryptographic integrity checks (TLS)
Let us learn more about Error Detection in TCP:
RFC: RFC 793 (TCP Protocol Specification)
Main Features:
Prevents sender from overwhelming the receiver by controlling data flow
Uses a window size field to advertise how much data the receiver can handle
Implements sliding window mechanism for efficient data transmission
Adjusts flow dynamically based on network and receiver conditions
Helps avoid packet loss and ensures smooth communication
Use Cases:
Maintaining reliable data transmission in varying network conditions
Supporting applications like web browsing, file transfer, and streaming
Preventing buffer overflow on slower receivers or congested networks
Optimizing throughput and minimizing retransmissions
Alternative Protocols:
UDP – No built-in flow control, relies on application layer
SCTP – Enhanced flow control with multistreaming support
QUIC – Flow control integrated with encryption and multiplexing
Let us learn more about Flow Control in TCP:
RFC: RFC 793 (TCP Protocol Specification)
Main Features:
Uses 16-bit port numbers to identify sending and receiving applications
Enables multiplexing of multiple connections on a single IP address
Ports range from 0 to 65535, with well-known ports (0-1023) assigned to common services
Distinguishes between source port and destination port in TCP headers
Supports simultaneous communication sessions between different applications or services
Use Cases:
Running multiple services (e.g., HTTP on port 80, SSH on port 22) on one device
Enabling client-server communication by specifying destination port on server
Allowing operating systems to manage multiple TCP connections concurrently
Supporting network firewalls and filters based on port numbers
Alternative Protocols:
UDP – Also uses port addressing but without connection-oriented guarantees
SCTP – Uses port addressing with multihoming support
QUIC – Uses UDP ports but adds multiplexed streams on top
Let us learn more about TCP Port Addressing:
RFC: RFC 793 (TCP Protocol Specification)
Main Features:
Uses a four-step handshake (FIN, ACK, FIN, ACK) to close a connection gracefully
Ensures all pending data is transmitted before the connection is fully terminated
Allows both sender and receiver to acknowledge connection closure separately
Prevents data loss by orderly shutdown of communication channels
Supports half-close where one side can stop sending data while still receiving
Use Cases:
Closing web connections after data transfer completion (HTTP)
Properly ending FTP or SSH sessions without abrupt termination
Avoiding data truncation in file transfers or streaming services
Ensuring clean session teardown in distributed applications
Alternative Protocols:
UDP – Connectionless, does not support graceful termination
SCTP – Supports graceful shutdown with multi-stream capabilities
QUIC – Uses different mechanisms for connection closure but ensures data integrity
Let us learn more about TCP Graceful Connection Termination:
RFC: RFC 2581 (TCP Congestion Control)
Main Features:
Mechanisms to prevent network congestion collapse by controlling the rate of data transmission
Uses algorithms like Slow Start, Congestion Avoidance, Fast Retransmit, and Fast Recovery
Adjusts the congestion window (cwnd) dynamically based on network feedback
Detects packet loss as a sign of congestion and reduces transmission rate accordingly
Helps maintain fairness and efficiency in shared network environments
Use Cases:
Avoiding network overload in internet backbone and enterprise networks
Ensuring stable performance in web browsing, streaming, and file transfers
Improving throughput and reducing packet loss during peak traffic periods
Managing traffic in data centers and cloud networks
Alternative Protocols:
QUIC – Implements congestion control at the user level with improved performance
SCTP – Uses similar congestion control techniques as TCP with multi-streaming
DCCP – Designed specifically for congestion-controlled datagram transport
Let us learn more about TCP Congestion Control:
RFC: RFC 793 (Transmission Control Protocol)
Main Features:
Provides a continuous, reliable byte-stream abstraction between applications
Data is delivered in order without message boundaries, unlike datagram protocols
Enables applications to send and receive data as a seamless flow of bytes
Supports full-duplex communication allowing simultaneous send and receive
Handles segmentation and reassembly of data transparently to the application
Use Cases:
Web browsing (HTTP/HTTPS), file transfers (FTP)
Remote login and command execution (SSH, Telnet)
Streaming services requiring reliable data flow
Any application requiring reliable, ordered delivery of data streams
Alternative Protocols:
UDP – Connectionless and message-oriented, without guaranteed delivery
SCTP – Supports message-oriented multi-streaming with reliability
QUIC – User-space protocol providing stream multiplexing over UDP
Let us learn more about TCP Stream-Oriented Communication:
RFC: RFC 793 (Transmission Control Protocol)
Main Features:
Ensures that data segments are delivered to the application in the exact order they were sent
Uses sequence numbers and acknowledgments to track and reorder out-of-sequence packets
Retransmits lost or corrupted packets to maintain data integrity and order
Critical for applications where order of data impacts functionality and correctness
Use Cases:
File transfers (FTP) requiring exact data sequence
Web browsing (HTTP/HTTPS) for proper page rendering
Email protocols (SMTP, IMAP) for message integrity
Remote terminal sessions (SSH, Telnet) for command execution accuracy
Alternative Protocols:
UDP – Does not guarantee ordering, suitable for real-time or loss-tolerant apps
SCTP – Supports ordered and unordered delivery with multiple streams
QUIC – Provides ordered delivery with improved latency over UDP
Let us learn more about TCP Ordered Delivery:
RFC: RFC 793 (Transmission Control Protocol)
Main Features:
Fixed 20-byte header (without options) containing essential control information
Includes fields such as Source Port, Destination Port, Sequence Number, Acknowledgment Number
Contains Control Flags (SYN, ACK, FIN, RST, PSH, URG) for connection management
Window Size for flow control, Checksum for error checking, and Urgent Pointer
Use Cases:
Establishing and managing TCP connections
Ensuring reliable and ordered data transfer
Flow control and congestion management during communication
Error detection and recovery
Alternative Protocols:
UDP Header – simpler, smaller header without reliability features
SCTP Header – supports multi-streaming and multi-homing features
QUIC Header – built on UDP, optimized for low latency and security
Let us learn more about the TCP Header:
RFC: RFC 793 (Transmission Control Protocol), RFC 7323 (TCP Extensions for High Performance)
Main Features:
Optional fields extending the basic TCP header, length varies up to 40 bytes total header size
Common options include Maximum Segment Size (MSS), Window Scale, Selective Acknowledgment (SACK), and Timestamps
Enhance performance, reliability, and support for high-speed networks
Options enable better flow control, congestion management, and improved error handling
Use Cases:
Negotiating maximum segment size during connection setup
Scaling window sizes for high bandwidth-delay product networks
Selective retransmission of lost packets using SACK
Round-trip time measurement and PAWS (Protection Against Wrapped Sequence numbers) using timestamps
Alternative Protocols:
TCP without options (minimum 20-byte header)
Other transport protocols (UDP, SCTP) with their own option fields
QUIC with built-in optimization features over UDP
Let us learn more about TCP Header Options:
RFC: RFC 1122, RFC 793, and various OS-level socket APIs
Main Features:
Configurable parameters that control TCP behavior during communication
Common options include TCP_NODELAY, SO_KEEPALIVE, SO_LINGER, TCP_MAXSEG, and TCP_CORK
Exposed via socket programming interfaces (e.g., setsockopt in C, Python’s socket module)
Improve performance, optimize behavior for specific applications or workloads
Use Cases:
TCP_NODELAY: Disables Nagle’s algorithm for low-latency applications like games or real-time chat
SO_KEEPALIVE: Detects dead peer connections in long-lived sessions
SO_LINGER: Controls how TCP handles socket close (graceful vs. abrupt)
TCP_CORK: Delays packet transmission until data is ready (used in HTTP servers)
TCP_MAXSEG: Sets the maximum segment size to control packet size
Alternative Protocols:
UDP (no connection-level options, minimal overhead)
QUIC (modern transport protocol with built-in performance tuning)
SCTP (includes both stream and message-oriented options)
Let us learn more about Common TCP-Level Options:
RFC: RFC 1122, POSIX Socket API Specification
Main Features:
Socket-level options control behavior of network sockets at the OS interface level
Applied using system calls like setsockopt() and getsockopt()
Include options for buffer size, reuse of addresses, timeout behavior, and more
Affects both performance and reliability of TCP applications
Use Cases:
SO_REUSEADDR: Allows a socket to forcibly bind to a port in TIME_WAIT
SO_RCVBUF / SO_SNDBUF: Tune buffer sizes for high-throughput or low-latency applications
SO_RCVTIMEO / SO_SNDTIMEO: Set socket timeouts for blocking calls
SO_LINGER: Determine behavior on close() — wait for unsent data or discard it
SO_BROADCAST: Enable sending datagrams to broadcast addresses (UDP)
Alternative Protocols:
UDP – Shares many socket options but lacks connection state
SCTP – Provides extended socket-level control with multiple streams
QUIC – Bypasses traditional sockets via user-space libraries
Let us learn more about TCP Socket-Level Options:
RFC: Not governed by a specific RFC – based on Linux kernel and sysctl configuration
Main Features:
TCP behavior in Linux is customizable using sysctl, /proc, and socket options
Fine-tuning parameters affects performance, security, congestion handling, and buffering
Commonly configured via /etc/sysctl.conf or runtime with sysctl -w
Allows optimization for high-performance servers, embedded systems, and networks
Use Cases:
`net.ipv4.tcp_syncookies`: Protects against SYN flood attacks
`net.ipv4.tcp_tw_reuse`: Allows reuse of sockets in TIME_WAIT state
`net.ipv4.tcp_fin_timeout`: Adjusts timeout for closed connections
`net.ipv4.tcp_window_scaling`: Enables support for large TCP windows
`net.core.rmem_max / wmem_max`: Set max socket receive/send buffer size
`net.ipv4.tcp_congestion_control`: Selects the congestion control algorithm (e.g., cubic, bbr)
Alternative Protocols:
BSD TCP stack – Alternative behavior and defaults in FreeBSD, macOS
Windows TCP/IP stack – Tuning through Registry settings
QUIC – User-space protocol not subject to kernel TCP settings
Let us learn more about TCP Linux Settings: