Tcp

17 min read3,266 words

TCP — Transmission Control Protocol

TCP (Transmission Control Protocol) is a connection-oriented, reliable transport-layer protocol used to deliver data between applications over an IP network.

Exam definition

TCP is a connection-oriented transport-layer protocol that provides reliable, ordered, error-checked delivery of data between applications using acknowledgments, sequence numbers, retransmissions, flow control, and congestion control.

TCP operates at:

OSI Model: Layer 4 → Transport TCP/IP Model: Transport Layer

1. Where TCP Fits

A typical web connection looks like:

Application │ │ HTTPS ↓ Transport │ │ TCP ↓ Internet │ │ IP ↓ Network Access │ │ Ethernet / Wi-Fi ↓ Network

For example:

HTTPS ↓ TCP ↓ IP ↓ Wi-Fi

TCP's job is mainly to provide reliable end-to-end transport between applications.

2. Why Do We Need TCP?

IP itself provides best-effort packet delivery.

IP does not guarantee that packets will:

  • Arrive
  • Arrive once
  • Arrive in order
  • Arrive without corruption
  • Be retransmitted if lost

TCP adds mechanisms to provide reliable communication.

For example, suppose the sender sends:

Packet 1 Packet 2 Packet 3 Packet 4

But Packet 2 is lost:

Packet 1 → ✓ Packet 2 → ✗ Packet 3 → ✓ Packet 4 → ✓

TCP can detect that data is missing and arrange for retransmission.

3. Main Features of TCP

TCP provides:

  1. Connection-oriented communication
  2. Reliable delivery
  3. Ordered delivery
  4. Error detection
  5. Retransmission
  6. Acknowledgments
  7. Sequence numbers
  8. Flow control
  9. Congestion control
  10. Full-duplex communication
  11. Byte-stream service
  12. Multiplexing using port numbers

These are the key characteristics you should remember.

4. TCP Is Connection-Oriented

Before normal application data is exchanged, TCP establishes a connection.

The basic process is:

Client Server │ │ │────── SYN ─────────────>│ │<──── SYN + ACK ─────────│ │────── ACK ─────────────>│ │ │ │══════ Data ═════════════│

This is called the:

TCP three-way handshake

5. TCP Three-Way Handshake

Let's understand each step.

Step 1 — SYN

The client sends a SYN segment.

Client → Server SYN

It is essentially saying:

"I want to establish a TCP connection."

The client chooses an initial sequence number.

Example:

SYN Sequence Number = 1000

Step 2 — SYN-ACK

The server responds:

Server → Client SYN + ACK

The server:

  • Acknowledges the client's SYN
  • Sends its own SYN
  • Chooses its own initial sequence number

Example:

ACK Number = 1001 SYN Sequence Number = 5000

Step 3 — ACK

The client responds:

Client → Server ACK

Example:

ACK Number = 5001

Now the connection is established.

6. Complete Handshake

Client Server │ │ │──── SYN, Seq=1000 ───────────────>│ │ │ │<── SYN+ACK, Seq=5000, Ack=1001 ───│ │ │ │──── ACK, Ack=5001 ───────────────>│ │ │ │ Connection Established │ │ │

After this, application data can be transmitted.

7. Why Three Steps?

Both sides need to establish that:

Client → Server communication works Server → Client communication works

The handshake also synchronizes initial sequence numbers.

So TCP knows the starting sequence-number state for each direction.

8. TCP Sequence Numbers

TCP uses sequence numbers to track bytes in the data stream.

Suppose the client sends:

HELLO

TCP does not simply think:

Packet 1

Instead, sequence numbers identify positions in the byte stream.

For example:

Sequence = 1000 Data = 100 bytes

The next byte would begin at:

1100

This allows TCP to:

  • Track data
  • Detect missing bytes
  • Reorder segments
  • Support retransmission

9. TCP Acknowledgments

The receiver sends an ACK to indicate the next byte it expects.

For example:

Sender Seq = 1000 Data = 500 bytes ↓ Receiver ACK = 1500

This means:

"I have received bytes up to 1499 and expect byte 1500 next."

This is a very important concept.

10. TCP Reliability

Suppose:

Sender → Segment 1 → Receiver Sender → Segment 2 → ✗ Sender → Segment 3 → Receiver

The receiver can indicate that some data is missing.

TCP can then retransmit the missing data.

Segment 2 ↓ Retransmission ↓ Receiver

This contributes to TCP's reliable delivery.

11. TCP Does Not Send "Packets"

Technically, TCP operates with:

TCP segments

The IP layer carries those TCP segments inside IP packets.

Simplified:

Application Data ↓ TCP Segment ↓ IP Packet ↓ Ethernet Frame

So:

TCP → Segment IP → Packet Ethernet → Frame

12. TCP Header

A TCP segment contains a TCP header followed by application data.

Simplified:

┌─────────────────────────────────────┐ │ Source Port │ ├─────────────────────────────────────┤ │ Destination Port │ ├─────────────────────────────────────┤ │ Sequence Number │ ├─────────────────────────────────────┤ │ Acknowledgment Number │ ├─────────────────────────────────────┤ │ Header Length / Flags │ ├─────────────────────────────────────┤ │ Window Size │ ├─────────────────────────────────────┤ │ Checksum │ ├─────────────────────────────────────┤ │ Urgent Pointer │ ├─────────────────────────────────────┤ │ Options (optional) │ ├─────────────────────────────────────┤ │ Application Data │ └─────────────────────────────────────┘

13. Important TCP Header Fields

Source Port

Identifies the sending application's transport endpoint.

Example:

52000

Destination Port

Identifies the destination service.

Example:

443

For HTTPS:

Client:52000 ↓ Server:443

Sequence Number

Tracks the position of bytes in the TCP stream.

Seq = 1000

Acknowledgment Number

Indicates the next byte expected.

ACK = 1500

Window Size

Used for flow control.

It tells the sender approximately how much additional data the receiver is currently prepared to accept without waiting for more acknowledgments.

Checksum

Used to detect corruption in the TCP segment.

Flags

TCP has several important control flags.

The most important are:

SYN ACK FIN RST PSH URG ECE CWR

Modern TCP also uses NS in the header specification, though it is much less commonly discussed in basic networking.

14. TCP Flags

SYN

Synchronize sequence numbers and establish a connection.

SYN = 1

Used during connection establishment.

ACK

Acknowledgment field is valid.

ACK = 1

Used in most segments after connection establishment.

FIN

Used to indicate that a side has finished sending data.

FIN = 1

Used for graceful connection termination.

RST

Reset the connection.

RST = 1

Can be used when a connection should be aborted or a segment cannot be accepted as part of a valid connection.

PSH

Historically associated with requesting that buffered data be delivered promptly to the receiving application.

It is often misunderstood; modern applications generally do not need to manipulate this flag directly.

URG

Indicates that the urgent pointer is significant.

It is rarely important in modern application design.

15. TCP Connection Establishment

Complete process:

TCP HANDSHAKE Client Server │ │ │────── SYN ──────────────────>│ │ │ │<──── SYN + ACK ──────────────│ │ │ │────── ACK ──────────────────>│ │ │ │ ESTABLISHED │

16. TCP Data Transfer

After the handshake:

Client Server │ │ │──── Data + Seq ─────────────>│ │<──────── ACK ────────────────│ │ │ │──── More Data ──────────────>│ │<──────── ACK ────────────────│

The actual exchange can be more complex because TCP uses mechanisms such as cumulative acknowledgments, delayed ACKs, retransmission, windows, and congestion control.

17. TCP Connection Termination

TCP normally uses a four-segment exchange to close a connection cleanly.

Client Server │ │ │──────── FIN ────────────────>│ │<──────── ACK ────────────────│ │<──────── FIN ────────────────│ │──────── ACK ────────────────>│ │ │ │ Connection Closed │

This can vary because one side may combine FIN and ACK in the same segment.

18. Why Four Steps?

TCP is full-duplex.

That means each side has an independent direction of data transmission.

So:

Client → Server

can be closed independently from:

Server → Client

A FIN means:

"I have finished sending data."

It does not necessarily mean:

"I can no longer receive data."

19. FIN vs RST

FIN

Graceful termination.

FIN ↓ "I am finished sending."

RST

Immediate reset/abort.

RST ↓ "Terminate/reset this connection."

So:

FIN → graceful RST → abrupt

20. TCP Flow Control

Flow control protects a slow receiver from being overwhelmed by a fast sender.

Example:

Fast Sender │ │ 100 MB/s ↓ Slow Receiver │ │ Can process only 10 MB/s

Without flow control, the receiver's buffers could overflow.

TCP uses a receive window to communicate how much data the receiver can currently accept.

21. TCP Window

Simplified example:

Receiver says: Window = 10,000 bytes

The sender should not have more than the permitted amount of unacknowledged data outstanding based on the advertised receive window.

As data is acknowledged and buffer space becomes available, the receiver can advertise more window space.

22. Flow Control vs Congestion Control

These are different concepts.

Flow Control

Protects the:

Receiver

from being overwhelmed.

Congestion Control

Protects the:

Network

from becoming overloaded.

Remember:

Flow control → Receiver Congestion control → Network

23. TCP Congestion Control

Imagine many devices send data through the same network:

PC 1 ──┐ PC 2 ──┤ PC 3 ──┼── Router ── Internet PC 4 ──┤ PC 5 ──┘

If everyone sends too much data:

Network congestion ↓ Packet loss / delay

TCP responds by adjusting its sending behavior.

Important concepts include:

  • Congestion window (cwnd)
  • Slow start
  • Congestion avoidance
  • Fast retransmit
  • Fast recovery

Exact behavior depends on the TCP congestion-control algorithm.

24. TCP Slow Start

Despite its name, slow start is designed to quickly discover available network capacity without immediately sending an enormous amount of traffic.

Conceptually:

Small sending window ↓ Increase ↓ Increase ↓ Increase ↓ Detect congestion ↓ Adjust sending rate

The exact growth and behavior depend on the TCP implementation.

25. TCP Retransmission

If TCP believes data has been lost, it can retransmit it.

Loss can be inferred through mechanisms such as:

  • Retransmission timeout
  • Duplicate acknowledgments
  • Selective acknowledgment information

Example:

Sender │ ├── Segment 1 ─────→ Receiver ├── Segment 2 ──X ├── Segment 3 ─────→ Receiver │ │ └── Retransmit Segment 2 ↓ Receiver

26. TCP Duplicate ACKs

Suppose the receiver receives:

Segment 1 Segment 3 Segment 4

but Segment 2 is missing.

The receiver may repeatedly acknowledge the next missing byte.

This can provide a signal that data may have been lost.

TCP can use such duplicate ACK patterns for fast retransmission.

27. Selective Acknowledgment — SACK

SACK stands for:

Selective Acknowledgment

It allows a receiver to provide more detailed information about which blocks of data have arrived.

For example:

Received: 1000–1999 3000–3999 4000–4999 Missing: 2000–2999

This helps the sender retransmit only the missing portion instead of unnecessarily retransmitting already received data.

28. TCP Is a Byte-Stream Protocol

TCP provides a continuous byte stream to the application.

Suppose the application sends:

HELLO WORLD

TCP does not preserve those as two separate messages.

The receiver may simply see:

HELLOWORLD

or data may be delivered in different-sized chunks.

Therefore:

TCP does not preserve application message boundaries.

Applications that need message boundaries must implement their own framing.

This is an important concept for programming and cybersecurity.

29. TCP vs UDP

FeatureTCPUDP
ConnectionConnection-orientedConnectionless
ReliabilityYesNo built-in guarantee
OrderingYesNo built-in guarantee
RetransmissionYesNo
ACKYesNo
Flow controlYesNo TCP-style flow control
Congestion controlYesNo TCP-style congestion control
OverheadHigherLower
Data modelByte streamDatagram/message-oriented
Common usesHTTPS, SSH, many application protocolsDNS, DHCP, real-time apps, QUIC

30. TCP Connection Example

Suppose you access:

https://example.com

A simplified flow:

Client Server 192.168.1.10 93.184.216.34 │ │ │──── SYN → TCP 443 ───────────────>│ │<─── SYN-ACK ──────────────────────│ │──── ACK ─────────────────────────>│ │ │ │──── TLS/Application data ────────>│ │<─── Response ─────────────────────│

Note that modern HTTPS can also run over QUIC/HTTP/3 using UDP, so not every HTTPS connection uses TCP.

31. TCP and HTTPS

Traditional HTTPS commonly uses:

HTTPS ↓ TLS ↓ TCP ↓ IP

For example:

TCP 443

But HTTP/3 uses:

HTTP/3 ↓ QUIC ↓ UDP ↓ IP

Therefore:

HTTPS does not universally mean TCP 443 anymore.

TCP remains extremely important for HTTP/1.1 and HTTP/2 deployments.

32. TCP Ports

TCP uses 16-bit port numbers:

0 – 65535

Examples:

22 → SSH 25 → SMTP 80 → HTTP 443 → HTTPS

A TCP endpoint can be represented as:

IP:Port

Example:

192.168.1.10:443

33. TCP Socket

A TCP connection is commonly identified using a 4-tuple:

Source IP Source Port Destination IP Destination Port

For example:

192.168.1.10:52000 ↓ 142.250.72.14:443

The protocol is TCP, so in many contexts this is described as a TCP flow.

34. TCP State Machine

TCP maintains connection states.

Important states include:

CLOSED LISTEN SYN-SENT SYN-RECEIVED ESTABLISHED FIN-WAIT-1 FIN-WAIT-2 CLOSE-WAIT LAST-ACK TIME-WAIT CLOSING

The most important for beginners are:

LISTEN ↓ SYN-SENT / SYN-RECEIVED ↓ ESTABLISHED ↓ FIN-WAIT / CLOSE-WAIT ↓ TIME-WAIT ↓ CLOSED

35. LISTEN

A server waits for incoming TCP connections.

Example:

Web Server │ └── LISTEN TCP 443

When a client sends SYN:

Client │ │ SYN ↓ Server │ └── SYN-RECEIVED

36. ESTABLISHED

After the handshake:

Client ↕ ESTABLISHED ↕ Server

Both sides can exchange data.

37. TIME-WAIT

After connection termination, one side may enter:

TIME-WAIT

This helps TCP handle delayed segments from an old connection and allows the final acknowledgment to be retransmitted if needed.

It is normal to see many TIME-WAIT sockets on busy servers.

38. TCP Checksum

TCP includes a checksum to help detect corruption.

Conceptually:

Sender ↓ Calculate checksum ↓ Send segment ↓ Receiver ↓ Verify checksum

If corruption is detected, the segment is not accepted as valid TCP data.

39. TCP Options

TCP supports optional features.

Important examples:

MSS

Maximum Segment Size

Defines the largest TCP payload a host is willing to receive in a segment.

Window Scaling

Allows TCP to advertise larger receive windows than the original 16-bit window field alone would permit.

SACK

Allows more precise reporting of received data blocks.

Timestamps

Can assist with RTT measurement and protection mechanisms such as PAWS.

40. MSS vs MTU

These are often confused.

MTU

Maximum size of an IP packet that can normally be carried over a link without fragmentation at that layer.

For common Ethernet:

MTU = 1500 bytes

MSS

Maximum TCP payload size.

For a typical IPv4 Ethernet path:

MTU = 1500 IPv4 header = 20 TCP header = 20 MSS ≈ 1460 bytes

This is a common example, not a universal value.

41. TCP Encapsulation

When an application sends data:

Application Data ↓ TCP Header + Data ↓ TCP Segment ↓ IP Header + TCP Segment ↓ IP Packet ↓ Ethernet Header + IP Packet + Trailer ↓ Ethernet Frame

So:

Data ↓ Segment ↓ Packet ↓ Frame

42. TCP in Wireshark

TCP traffic can be inspected using Wireshark.

You may see:

[SYN] [SYN, ACK] [ACK] [PSH, ACK] [ACK] [FIN, ACK] [ACK]

A useful display filter is:

tcp

You can also inspect:

tcp.flags.syn

or:

tcp.flags.fin

or:

tcp.flags.reset

This is useful for learning how TCP actually behaves on a network.

43. TCP in Linux

You can inspect TCP sockets with:

ss -t

For listening TCP ports:

ss -ltn

For TCP connections and processes:

ss -lntp

Example:

LISTEN 0 128 0.0.0.0:22

This means a process is listening for TCP connections on port 22 on the displayed local address.

44. TCP Security Perspective

TCP itself does not provide encryption.

For example:

TCP

does not automatically mean:

Encrypted

Security is usually provided by higher-level protocols.

For example:

HTTPS ↓ TLS ↓ TCP

SSH:

SSH ↓ TCP

So:

TCP provides transport reliability, not application-level confidentiality.

45. TCP SYN Flood

A SYN flood is a type of denial-of-service attack involving large numbers of TCP connection initiation attempts.

Simplified:

Attacker │ ├── SYN ──→ Server ├── SYN ──→ Server ├── SYN ──→ Server ├── SYN ──→ Server └── ...

The server may maintain many partially established connections.

Defensive technologies can include:

  • SYN cookies
  • Rate limiting
  • Firewalls
  • Load balancers
  • DDoS protection
  • Connection limits

This is important from a network-security perspective.

46. TCP Reset — RST

A TCP RST can immediately terminate/reset a connection.

For example:

Client │ │ Request ↓ Server │ │ RST ↓ Connection reset

Possible causes include:

  • No service listening on the port
  • Invalid connection state
  • Application/system deciding to abort
  • Network/security device interference

The exact meaning depends on the context.

47. TCP Three-Way Handshake — Exam View

Client Server SYN Seq = X ──────────────────────────────> SYN + ACK Seq = Y Ack = X+1 <────────────────────────────── ACK Seq = X+1 Ack = Y+1 ──────────────────────────────> CONNECTION ESTABLISHED

Remember:

SYN ↓ SYN + ACK ↓ ACK

48. TCP Termination — Exam View

Client Server FIN ──────────────────────────────> ACK <────────────────────────────── FIN <────────────────────────────── ACK ──────────────────────────────>

Remember:

FIN ↓ ACK ↓ FIN ↓ ACK

The exact packets can vary, including FIN+ACK combinations.

49. TCP vs IP

Don't confuse these two.

IP

Responsible primarily for:

Logical addressing Routing Packet forwarding

TCP

Responsible primarily for:

Reliable transport Ordering Retransmission Flow control Congestion control

Together:

TCP ↓ IP

TCP provides transport services while IP moves packets between networks.

50. TCP vs MAC

MAC ↓ Local link communication IP ↓ Network-to-network routing TCP ↓ Reliable application-to-application transport

Example:

Application ↓ TCP → Port 443 ↓ IP → Destination IP ↓ Ethernet → Destination MAC

51. Complete TCP Communication

APPLICATION │ HTTPS / SSH │ ↓ TCP │ ┌──────────┼──────────┐ │ │ │ Ports Sequence ACKs Numbers │ │ │ └──────────┼──────────┘ ↓ IP ↓ Ethernet / Wi-Fi ↓ Network

52. TCP — Quick Revision

Full form

Transmission Control Protocol

Layer

OSI → Layer 4 TCP/IP → Transport

Main characteristics

Connection-oriented Reliable Ordered Full-duplex Byte-stream Flow control Congestion control Retransmission Acknowledgments Sequence numbers

Handshake

SYN ↓ SYN-ACK ↓ ACK

Termination

FIN ↓ ACK ↓ FIN ↓ ACK

Important flags

SYN → Establish ACK → Acknowledge FIN → Graceful close RST → Reset

Common TCP ports

22 → SSH 25 → SMTP 80 → HTTP 443 → HTTPS

Data unit

Application → Data TCP → Segment IP → Packet Ethernet → Frame

One-line exam answer

TCP is a connection-oriented and reliable transport-layer protocol that provides ordered, error-checked delivery of a byte stream using sequence numbers, acknowledgments, retransmissions, flow control, and congestion control.

Keep learning. Keep building. Keep growing.

© 2026 Ugenz Academy