TCP/IP Stack

The TCP/IP (Transmission Control Protocol/Internet Protocol) stack is a set of networking protocols used for communication over the internet and other networks. It consists of four layers, each with specific functions.


1. Application Layer

  • The top layer of the stack, responsible for interacting with applications that use network communication.

  • It prepares data for transmission by using appropriate protocols.

  • Common protocols include:

    • HTTP (HyperText Transfer Protocol) – Used for web browsing.

    • HTTPS (Secure HTTP) – Encrypts web traffic for security.

    • FTP (File Transfer Protocol) – Transfers files between computers.

    • SMTP (Simple Mail Transfer Protocol) – Sends emails.

    • IMAP (Internet Message Access Protocol) – Retrieves emails.


2. Transport Layer

  • Manages end-to-end communication between devices.

  • Ensures data is broken into packets and reassembled correctly at the destination.

  • Uses two main protocols:

    • TCP (Transmission Control Protocol) – Provides reliable, ordered delivery of packets with error checking and retransmission.

    • UDP (User Datagram Protocol) – A faster but less reliable alternative, often used for live streaming and online gaming.


3. Internet Layer (Network Layer)

  • Handles routing of data across different networks.

  • Uses IP (Internet Protocol) to assign unique addresses to devices and ensure data reaches the correct destination.

  • Uses two key protocols:

    • IP (Internet Protocol) – Assigns IP addresses and handles packet forwarding.

    • ICMP (Internet Control Message Protocol) – Sends error messages and diagnostics (e.g., "destination unreachable").


4. Link Layer (Network Interface Layer)

  • The lowest layer, responsible for transmitting data over physical network hardware (e.g., Ethernet, Wi-Fi).

  • Ensures that data is correctly formatted for the physical connection.

  • Uses MAC (Media Access Control) addresses to identify devices on a local network.


Summary of the TCP/IP Stack

Layer NamePurposeExample Protocols

Application Layer

Provides services to applications

HTTP, FTP, SMTP

Transport Layer

Splits data into packets, ensures correct delivery

TCP, UDP

Internet Layer

Routes packets using IP addresses

IP, ICMP

Link Layer

Controls physical network connections

Ethernet, Wi-Fi

Each layer only communicates with the layer directly above or below it, making the network more efficient and structured. The TCP/IP model is the foundation of the internet and modern networking.

Application Layer Protocols

1. HTTP (Hypertext Transfer Protocol)

  • Used for transferring web pages over the internet.

  • Works in a client-server model, where the client (web browser) requests a web page, and the server responds with the required content.

  • Uses request-response cycles:

    • GET request – Requests a web page from a server.

    • POST request – Sends data to a server (e.g., form submission).

  • HTTP is stateless, meaning it does not remember previous requests.

Limitations of HTTP

  • Data is not encrypted, making it vulnerable to hacking and interception.

  • No authentication is built-in, allowing for man-in-the-middle attacks.


2. HTTPS (Hypertext Transfer Protocol Secure)

  • A secure version of HTTP, using SSL/TLS encryption to protect data.

  • Encrypts the communication between the client and the web server, preventing interception or tampering.

  • Commonly used for online banking, e-commerce, and secure logins.

How HTTPS Works

  1. The browser requests a secure connection to the server.

  2. The server sends an SSL/TLS certificate to verify its identity.

  3. The browser and server establish an encrypted connection using a secure key exchange.

  4. The encrypted communication begins.

Benefits of HTTPS

  • Data confidentiality – Encrypts data to prevent eavesdropping.

  • Authentication – Verifies the identity of the server.

  • Data integrity – Ensures data is not altered in transit.


3. FTP (File Transfer Protocol)

  • Used for transferring files between a client and a server over a network.

  • Supports two modes of operation:

    • Active mode – The server opens a connection back to the client.

    • Passive mode – The client opens both connections (safer behind firewalls).

How FTP Works

  1. The user logs into an FTP server using a username and password.

  2. The client can upload, download, or delete files on the server.

  3. Files are transferred in binary (for software) or ASCII mode (for text).

Limitations of FTP

  • No encryption, meaning data is sent in plaintext (vulnerable to attacks).

  • Replaced by SFTP (Secure FTP), which encrypts file transfers.


4. SMTP (Simple Mail Transfer Protocol)

  • Used for sending emails from a client to a mail server.

  • Works by routing emails between different servers until they reach their destination.

How SMTP Works

  1. The email client sends the message to an SMTP server.

  2. The SMTP server forwards the email to the recipient’s mail server.

  3. The recipient retrieves the email using IMAP or POP3.

Limitations of SMTP

  • Only handles sending emails, not receiving them.

  • Lacks built-in security, making encryption (e.g., TLS) necessary.


5. IMAP (Internet Message Access Protocol)

  • Used for retrieving emails from a mail server.

  • Unlike POP3, IMAP stores emails on the server, allowing users to access them from multiple devices.

How IMAP Works

  1. The email client connects to the mail server and retrieves only the email headers.

  2. The user can read emails without downloading them, as they stay on the server.

  3. When an email is deleted, it is removed from the server for all devices.

Benefits of IMAP

  • Allows multiple device access (ideal for modern email use).

  • Emails are backed up on the server.

  • Faster as only necessary parts of emails are downloaded.


6. POP3 (Post Office Protocol v3)

  • Used for retrieving emails, but unlike IMAP, it downloads emails to a single device and deletes them from the server.

How POP3 Works

  1. The email client connects to the mail server.

  2. All emails are downloaded to the user’s device.

  3. Emails are removed from the server once downloaded.

Limitations of POP3

  • Emails cannot be accessed from multiple devices.

  • If the device is lost, emails are permanently gone unless backed up.

  • IMAP is preferred over POP3 for modern email usage.


Summary of Application Layer Protocols

ProtocolPurposeKey Features

HTTP

Loads web pages

Stateless, no encryption

HTTPS

Secure web browsing

Uses SSL/TLS encryption

FTP

Transfers files

No encryption, replaced by SFTP

SMTP

Sends emails

Handles outgoing mail only

IMAP

Retrieves emails

Stores emails on the server, multi-device access

POP3

Retrieves emails

Downloads and deletes emails from the server

Each protocol is designed for a specific function, and together they enable efficient communication over the internet

Transport Layer Protocols

The Transport Layer of the TCP/IP stack is responsible for managing data transmission between devices. It ensures that data is sent, received, and reassembled correctly. The two main protocols used in this layer are:

  1. TCP (Transmission Control Protocol) – Provides reliable, error-checked communication.

  2. UDP (User Datagram Protocol) – Provides fast, connectionless communication with no guarantee of delivery.


1. TCP (Transmission Control Protocol)

TCP is a connection-oriented protocol, meaning it establishes a reliable connection before data is transmitted. It ensures that all packets arrive in order and without errors.

How TCP Works (Step-by-Step Process)

  1. Connection Establishment (Three-Way Handshake)

    • The sender sends a SYN (synchronize) packet to request a connection.

    • The receiver responds with a SYN-ACK (synchronize-acknowledge) packet.

    • The sender replies with an ACK (acknowledge) packet, and the connection is established.

  2. Data Transmission

    • The data is divided into packets and assigned a sequence number.

    • Each packet is checked for errors using checksums.

    • The receiver acknowledges each received packet.

  3. Retransmission of Lost Packets

    • If a packet is lost or arrives corrupted, the receiver requests a retransmission.

    • The sender resends the missing packet to ensure complete data transfer.

  4. Connection Termination

    • Either device can initiate termination by sending a FIN (finish) packet.

    • The receiver responds with an ACK.

    • Once both sides acknowledge, the connection is closed.

Advantages of TCP

Reliable – Ensures all data is received correctly and in order.
Error-checked – Corrupted or missing packets are resent.
Used for important communications, such as web browsing, file transfers, and emails.

Disadvantages of TCP

Slower than UDP due to its error-checking and retransmission processes.
More overhead due to the need for acknowledgments and retransmissions.


2. UDP (User Datagram Protocol)

UDP is a connectionless protocol, meaning it sends data without establishing a connection. It does not guarantee delivery, order, or error checking.

How UDP Works (Step-by-Step Process)

  1. The sender divides data into datagrams (similar to packets).

  2. Datagrams are sent to the receiver without acknowledgments.

  3. If a datagram is lost, UDP does not request retransmission.

  4. The receiver processes whatever datagrams arrive, but some may be missing or out of order.

Advantages of UDP

Fast – No need for acknowledgments or retransmissions.
Efficient – Uses less bandwidth and processing power.
Ideal for real-time applications, such as video streaming, online gaming, and VoIP (voice calls).

Disadvantages of UDP

Unreliable – No guarantee that all data will arrive.
Packets may be lost – No retransmission if data is missing.
No error checking – Corrupt packets may still be delivered.


Comparison of TCP vs UDP

Feature

TCP (Transmission Control Protocol)

UDP (User Datagram Protocol)

Connection Type

Connection-oriented (establishes a connection)

Connectionless (no connection)

Reliability

Reliable – ensures all data arrives correctly

Unreliable – no guarantee of delivery

Packet Ordering

Packets arrive in order

Packets may arrive out of order

Error Checking

Uses error checking and retransmission

Minimal error checking, no retransmission

Speed

Slower due to acknowledgments and retransmission

Faster due to no retransmission

Use Cases

Web browsing (HTTP/HTTPS), emails (SMTP/IMAP), file transfers (FTP)

Video streaming, online gaming, VoIP (Skype, WhatsApp calls)


When to Use TCP vs UDP

  • Use TCP when accuracy and reliability are important (e.g., loading web pages, sending emails, downloading files).

  • Use UDP when speed and efficiency are more important than reliability (e.g., live video streaming, online gaming, voice calls).

TCP and UDP are both essential in networking, each suited for different types of data transmission.

Internet Layer Protocols

The IP (Internet Protocol) is a fundamental part of the TCP/IP stack and is used in the Internet Layer. It is responsible for addressing, routing, and delivering data packets between devices across networks, including the internet.


1. Purpose of IP (Internet Protocol)

The IP protocol performs three key functions:

  1. Addressing – Assigns a unique IP address to each device on a network.

  2. Packetization – Breaks data into smaller packets for transmission.

  3. Routing – Determines the best path for packets to travel across networks.

Each packet contains the source IP address (sender’s address) and the destination IP address (receiver’s address) to ensure it reaches the correct device.


2. IP Addressing

Every device connected to a network has an IP address, which is a unique numerical identifier used for communication. There are two main types of IP addresses:

IPv4 (Internet Protocol version 4)

  • Uses a 32-bit address format, written as four decimal numbers separated by dots (e.g., 192.168.1.1).

  • Example:

    CopyEdit

    192.168.0.10 172.16.254.1 8.8.8.8

  • IPv4 allows for about 4.3 billion unique addresses, but this is not enough due to the rapid growth of internet-connected devices.

IPv6 (Internet Protocol version 6)

  • Uses a 128-bit address, written in hexadecimal and separated by colons (e.g., 2001:db8::ff00:42:8329).

  • Example:

    makefile

    CopyEdit

    2001:0db8:85a3:0000:0000:8a2e:0370:7334

  • Provides a much larger address space (trillions of unique IP addresses), solving the shortage of IPv4 addresses.


3. IP Packet Structure

When data is sent over a network, it is divided into packets. Each IP packet has a header and a payload:

ComponentDescription

Header

Contains control information, such as source IP, destination IP, packet length, and time-to-live (TTL).

Payload

Contains the actual data being transmitted.

Key Fields in an IP Header

  1. Source IP Address – Identifies the sender’s device.

  2. Destination IP Address – Identifies the receiver’s device.

  3. Packet Length – Defines the total packet size.

  4. Time-To-Live (TTL) – Specifies how long a packet can stay in the network before being discarded.

  5. Checksum – Ensures the packet is not corrupted.


4. Routing in IP

IP uses routers to move packets from the sender to the receiver across multiple networks.

How Routing Works

  1. A router receives a packet and reads the destination IP address.

  2. It looks at its routing table to find the best path to the destination.

  3. The router forwards the packet to the next router or the destination device.

  4. The process repeats until the packet reaches its final destination.

Routers play a crucial role in directing traffic efficiently across networks.


5. Connectionless Nature of IP

The IP protocol is connectionless, meaning:
Packets are sent independently without establishing a connection first.
Packets may take different routes to the destination.
Packets may arrive out of order and must be reassembled at the destination.

Because IP does not guarantee reliable delivery, it is often used with TCP, which provides error checking and packet reordering.


6. Limitations of IP

No built-in error checking – If packets are lost or corrupted, they are not automatically resent.
No packet ordering – Packets may arrive out of order, requiring TCP for reassembly.
Security concerns – IP addresses can be spoofed, leading to cyber attacks (e.g., DDoS attacks).


Summary of IP Protocol

Feature Description

Layer

Internet Layer (TCP/IP Stack)

Purpose

Addressing and routing packets

Addressing

Uses IPv4 (32-bit) or IPv6 (128-bit)

Connection Type

Connectionless (does not establish a connection)

Reliability

No error checking or packet ordering

Works with

TCP (for reliability) or UDP (for speed)

Final Notes

  • IP is essential for identifying devices and routing data across the internet.

  • IPv6 is replacing IPv4 due to a shortage of available addresses.

  • Routers play a key role in directing IP packets to the correct destination.

Together with TCP or UDP, IP ensures that data is efficiently transmitted across networks.

Link Layer Protocol

The Ethernet protocol is a key standard used in wired networks to define how data is formatted, transmitted, and received within a local area network (LAN). It operates at the Link Layer (also known as the Network Interface Layer) of the TCP/IP stack and ensures that data is transmitted efficiently and reliably between devices connected via cables (e.g., twisted-pair, coaxial, or fiber optic cables).


1. Purpose of Ethernet

Ethernet is responsible for:
Defining communication rules for wired networks.
Ensuring reliable data transfer within a LAN.
Handling error detection in transmitted data.
Identifying devices using MAC addresses.

Ethernet is the most common wired networking standard and is used in homes, schools, and businesses to connect devices like computers, routers, and switches.


2. How Ethernet Works

Ethernet transmits data in the form of frames, which contain important information about the sender, receiver, and the actual data being sent.

Ethernet Frame Structure

Each Ethernet frame consists of several sections:

FieldDescription

Preamble

A sequence of bits that signals the start of a frame.

Destination MAC Address

Identifies the receiving device.

Source MAC Address

Identifies the sender’s device.

Payload (Data)

The actual data being transmitted.

FCS (Frame Check Sequence)

A checksum used to detect transmission errors.

How an Ethernet Frame is Transmitted

  1. The sender creates an Ethernet frame containing the destination MAC address, source MAC address, and data.

  2. The frame is sent over the network cable to the recipient.

  3. Switches and routers direct the frame to the correct device.

  4. The receiving device checks for errors using the FCS (Frame Check Sequence) and, if valid, processes the data.


3. MAC Addresses and Ethernet

Ethernet uses MAC addresses (Media Access Control addresses) to identify devices on a network.

  • A MAC address is a unique 48-bit identifier assigned to a network interface card (NIC).

  • MAC addresses are written in hexadecimal format, e.g., 00:1A:2B:3C:4D:5E.

  • Ethernet delivers frames to specific MAC addresses instead of using IP addresses (which operate at a higher layer).

This makes Ethernet ideal for local communication within a LAN.


4. Collision Detection & Avoidance in Ethernet

Before transmitting data, Ethernet ensures that devices avoid sending data at the same time, which could cause a collision (when two devices send data simultaneously).

Older Method: CSMA/CD (Carrier Sense Multiple Access with Collision Detection)

In older Ethernet networks (using hubs), a method called CSMA/CD was used:

  1. Devices listen to the network before transmitting.

  2. If the network is busy, they wait.

  3. If two devices transmit at the same time, a collision occurs.

  4. Both devices stop sending and wait a random amount of time before retrying.

Modern Method: Full-Duplex Switching

Modern Ethernet networks use switches instead of hubs, meaning:
Devices transmit and receive data simultaneously (full-duplex).
Collisions are eliminated since each device has a direct connection.


5. Ethernet Cable Types

Ethernet works with different types of cables, depending on speed and distance requirements:

Cable TypeSpeedMax DistanceUsage

Cat5

Up to 100 Mbps

100m

Basic networking

Cat5e

Up to 1 Gbps

100m

Home networks

Cat6

Up to 10 Gbps

55m

High-speed LANs

Fiber Optic

100+ Gbps

Several km

Long-distance, fast data transfer

Modern Ethernet networks mostly use Cat5e or Cat6 cables.


6. Advantages of Ethernet

Reliable – Uses error checking to detect corrupted data.
Fast – Supports high data transfer speeds (1 Gbps and beyond).
Secure – Harder to intercept than Wi-Fi since it requires physical access.
Cost-effective – Ethernet cables and switches are affordable and widely available.


7. Limitations of Ethernet

Limited Mobility – Devices must be physically connected via cables.
Installation Can Be Complex – Requires running cables through walls and floors.
Expensive for Large Networks – Requires switches, routers, and extensive cabling.


8. Summary of Ethernet Protocol

FeatureDescription

Layer

Link Layer (TCP/IP Stack)

Purpose

Wired communication within a LAN

Uses

Ethernet frames and MAC addresses

Error Checking

Frame Check Sequence (FCS)

Collision Avoidance

Uses CSMA/CD (older) or switches (modern)

Speed

100 Mbps – 100 Gbps

Cables

Cat5, Cat5e, Cat6, Fiber Optic


Final Notes

  • Ethernet is the standard for wired LANs and provides fast, secure, and reliable communication.

  • It transmits data in frames and uses MAC addresses for delivery.

  • Modern networks use Ethernet switches to eliminate collisions and improve efficiency.

  • Ethernet remains widely used, even with the rise of Wi-Fi.

robot