Skip to content

TCP and IP Header, Window Size, Segment, Packet and Frame

1. TCP Header (Transport Layer)

0 8 16 31 (bits)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Source Port β”‚ Destination Port β”‚ Sequence Number β”‚
β”‚ (16b) β”‚ (16b) β”‚ (32b) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Acknowledgment Number (32b) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Data Off (4b) β”‚ Reserved (3b) β”‚ Flags (9b) β”‚ Window Size (16b) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Checksum (16b) β”‚ Urgent Pointe (16b) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Options (0–40 bytes) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Data β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • Size:
    • 20 bytes (without options)

    • 20–60 bytes (with options).
  • Purpose:
    • Reliable delivery, flow control, and connection management.
  • Key Fields:
    • Source Port (16B), Destination Port (16B) – identifies sending/receiving apps
    • Sequence Number (32B) – order of bytes
    • Acknowledgment Number (32B) – confirms received bytes
    • Data Offset (4B) – TCP header length
    • Flags (9 bits) – SYN, ACK, FIN, RST, PSH, URG
    • Window Size (16B) – flow control / in-flight data limit
    • Checksum (16B) – error detection
    • Urgent Pointer (16B) – optional
    • Options (variable) – optional, max header 60B
  • Function: Ensures reliable, ordered, and flow-controlled delivery of data.

2. IP Header (Network Layer)

IPv4 Header ⭐

  • Size:
    • 20 bytes (without options)

    • 20–60 bytes (with options).
  • Purpose:
    • Routing data from source to destination across networks.
  • Key Fields:
    • Version (4B) – IPv4/IPv6
    • Header Length (4B) – length of IP header
    • Type of Service / DSCP (8B) – priority / QoS
    • Total Length (16B) – IP packet size (header + data)
    • Identification / Flags / Fragment Offset – fragmentation control
    • TTL (8B) – Time to Live, decremented at each hop
    • Protocol (8B) – indicates encapsulated protocol (TCP=6, UDP=17)
    • Header Checksum (16B) – error detection
    • Source IP / Destination IP (32B each) – identifies endpoints
    • Options (variable) – rarely used
  • Function: Routes the packet across networks, handles fragmentation, and identifies endpoints.

IPv6 Header

  • Size: 40 bytes (fixed)

    • Unlike IPv4, IPv6 header does not have variable length unless there are extension headers.
  • Purpose: Routing packets across networks, similar to IPv4, but simplified for faster processing and larger address space.
  • Key Fields (Fixed 40 bytes):
    1. Version (4 bits): Always 6
    2. Traffic Class (8 bits): Like IPv4 DSCP, for QoS
    3. Flow Label (20 bits): For special routing of flows
    4. Payload Length (16 bits): Length of data after header
    5. Next Header (8 bits): Indicates transport protocol (TCP=6, UDP=17)
    6. Hop Limit (8 bits): Replaces TTL, decremented at each hop
    7. Source Address (128 bits)
    8. Destination Address (128 bits)
  • Notes:
    • No Header Checksum β†’ routers don’t recompute, faster processing
    • No Fragmentation fields β†’ fragmentation handled by source host, not routers
    • Extension Headers: Optional, separate from main 40-byte header

IPv4 header diagram

0 8 13 31 (bits)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Version β”‚ IHL β”‚ Type of Ser.β”‚ Total Length β”‚
β”‚ (4b) β”‚ (4b) β”‚ (8b) β”‚ (16b) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Identification (16b) β”‚ Flags (3b) β”‚ Frag Offset (13b) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Time To Live (8b) β”‚ Protocol (16b) β”‚ Header Checksum (8b) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Source IP Address (32b) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Destination IP Address (32b) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Options (0–40 bytes) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Changes in Transit

1. TCP Header Fields & Changes in Transit

FieldSizeChanges During Transit?Why / Notes
Source Port16bNoApplication port of sender
Destination Port16bNoApplication port of receiver
Sequence Number32bNoAssigned by sender, stays same
Acknowledgment Number32bNoSet by receiver, does not change mid-transit
Data Offset4bNoHeader length, constant
Reserved3bNoAlways 0
Flags9bNoSYN, ACK, FIN, etc. are fixed per segment
Window Size16bNoFlow control; fixed in segment
Checksum16bRecomputed if any field changesUsually unchanged; only if network modifies bits (rare)
Urgent Pointer16bNoOnly used if URG flag set
Options0–40BNoUsually unchanged
DataVariableNoPayload unchanged
  • TCP headers do not change during transit, except rarely for checksum if bits are corrupted and fixed.

2. IPv4 Header Fields & Changes in Transit

FieldSizeChanges During Transit?Why / Notes
Version4bNoAlways 4 for IPv4
IHL (Header Length)4bNoConstant per packet
Type of Service / DSCP8bSometimesRouters may set QoS bits for priority
Total Length16bNoIncludes header + payload; does not change
Identification16bNoSame for all fragments
Flags3b==Fragmentation may set MF (More Fragments)==If packet fragmented
Fragment Offset13b==Changes if fragmented==Indicates position of fragment
TTL (Time To Live)8b==Decrements at each hop==Prevents loops; drops at 0
Protocol8bNoIdentifies transport layer protocol (TCP=6)
Header Checksum16b==Recomputed at each hop==Because TTL changes, checksum changes
Source IP32bNoOriginal sender IP
Destination IP32bNoFinal receiver IP
OptionsvariableRarelyUsually unchanged
  • Only TTL== and ==Header Checksum always change at routers. ⭐

  • Fragmentation fields (Flags, Fragment Offset==) change only ==if packet is fragmented.

Key Differences

FeatureTCP HeaderIP Header
LayerTransportNetwork
Size20–60B20B
PurposeReliability, sequencing, flow controlRouting, addressing
Key FieldSequence Number, Window Size, FlagsSource IP, Destination IP, TTL
AffectsTCP Segment size, in-flight dataPacket routing, total packet size

Field Changes during Transit

  • Network (IP) β†’ TTL, Checksum, Fragmentation fields may change. ⭐

  • Transport (TCP) β†’ Usually nothing changes.

1. TCP Window Size

  • Max application data sender can send without ACK.

  • Measured in bytes, controls in-flight data.

  • Does not include headers, only counts payload.
Throughput = min(Window size / RTT, Link bandwidth)

2. TCP Segment

  • TCP payload + TCP header (20–60B).

  • Carries application data for transport.
  • Segment size limited by MSS:
MSS = MTU – IP header – TCP header

3. IP Packet

  • Segment + IP header (20B).

  • IP packet = TCP segment + IP header.
  • Packet is what network layer transmits to next hop.

4. Frame (Data Link Layer)

  • Packet + Link header + trailer (Ethernet example: 14B + 4B).

  • Max frame size limited by MTU (typically 1500B Ethernet).
  • Physical layer transmits bits of frame.

Quick Comparison & Relation

Relationship / Flow

Application Data
↓
TCP Segment = TCP header + data
↓
IP Packet = IP header + TCP segment
↓
Frame = Link header + IP packet + trailer
↓
Bits on wire

Comparison Table

TermSizeIncludesRoleRelation to Window Size
TCP Window SizeBytesOnly TCP payloadMax in-flight dataControls throughput
TCP SegmentTCP payload + TCP header (20–60B)TCP header + dataTransport unitMust fit in window
IP PacketSegment + IP header (20B)TCP + IP headers + dataNetwork unitSize affects MSS
FramePacket + Link header + trailerTCP/IP headers + data + Link headersPhysical transmissionMTU limits max segment size

Key Points to Understand:

  • Window size β†’ logical, controls how many bytes can be β€œin-flight”.
  • Segment / Packet / Frame β†’ physical encapsulations, headers reduce actual data per unit.
  • Header sizes β†’ overhead, reduce payload per transmission.
  • Frame size / MTU β†’ limits maximum segment size (MSS).

TCP Data Units, Window Size, and Bandwidth–Delay Product (BDP)

Section titled β€œTCP Data Units, Window Size, and Bandwidth–Delay Product (BDP)”

Data Units in Networking

  1. Bit – Smallest unit of data (0 or 1).
  2. Byte – 8 bits.
  3. Segment (TCP Layer)
    • Contains TCP header + application data.
    • TCP header: 20–60 bytes.
    • TCP segment = piece of application data ready to send.
  4. Packet (Network/IP Layer)
    • TCP segment is wrapped in IP header β†’ becomes packet.
    • IP header: 20 bytes.
    • Packet = TCP segment + IP header.
  5. Frame (Data Link Layer)
    • Packet is wrapped in Link Layer header + trailer β†’ Frame.
    • Ethernet example: Header = 14 bytes, Trailer (FCS) = 4 bytes.
    • Frame = Packet + Link Layer header + trailer.
  6. On-the-Wire
    • Physical layer transmits frames as bits.

Flow Diagram (Layer-wise)

Application Data
↓
TCP Segment (TCP Header + Data)
↓
IP Packet (IP Header + TCP Segment)
↓
Ethernet Frame (Link Header + Packet + Trailer)
↓
Bits transmitted on physical medium

TCP Window Size

  • Definition: Maximum amount of data sender can send without receiving ACK from receiver.
  • Measured in bytes.
  • Purpose: Controls β€œin-flight” data to match network capacity.

Key Concept:

  • Link can hold only limited bits at a time β†’ called Bandwidth–Delay Product (BDP).
  • TCP window size must be β‰₯ BDP to fully utilize the link.

Equation:

BDP (bits) = Link bandwidth (bits/sec) Γ— Round Trip Time (sec)
TCP Window Size (bytes) β‰₯ BDP / 8

Why Window Size Matters

  1. If TCP window < BDP:
    • Sender stops after sending window-sized data, waits for ACK.
    • Link capacity is not fully used β†’ throughput < max bandwidth.
  2. If TCP window β‰₯ BDP:
    • Sender continuously sends data β†’ link is full β†’ max throughput achieved.

Visualization:

Link capacity = pipe
BDP = pipe volume
Window size = amount sender can push into pipe at once
Window < BDP β†’ pipe not full β†’ wasted capacity
Window β‰₯ BDP β†’ pipe full β†’ maximum data in-flight

Relationship Between Units, Window, and Throughput

  • Data flows as: Application β†’ TCP Segment β†’ IP Packet β†’ Frame β†’ Bits on wire.
  • Window size controls how many TCP segments are in-flight.
  • BDP tells ideal number of bits in-flight to fully utilize link.
  • Throughput = min (Link capacity, Window/RTT)

Throughput Equation:

Throughput = TCP Window Size / RTT (bytes/sec)
If Window < BDP β†’ Throughput < Bandwidth
If Window β‰₯ BDP β†’ Throughput β‰ˆ Bandwidth

Summary Table

LayerUnitHeaderContentIn-Flight Control
ApplicationData-User info-
TransportSegment20–60BTCP header + DataTCP Window
NetworkPacket20BIP header + Segment-
LinkFrame14B+4BPacket + Header + Trailer-
PhysicalBits-Frame bitsControlled indirectly by Window & BDP