> ## Documentation Index
> Fetch the complete documentation index at: https://programming-for-career.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# TCP/IP Basics

> A comprehensive guide to the TCP/IP model, covering its layers, protocols, data transmission, addressing, and real-world applications.

## Introduction

The **TCP/IP (Transmission Control Protocol/Internet Protocol)** model is the foundation of modern networking, enabling communication between devices across the internet. It defines how data is transmitted, routed, and received across networks.

## Layers of the TCP/IP Model

TCP/IP is a **four-layered** model that simplifies network communication compared to the OSI model.

```mermaid theme={null}
graph TD;
    Application[Application Layer] -->|Data| Transport[Transport Layer];
    Transport -->|Segments| Internet[Internet Layer];
    Internet -->|Packets| NetworkAccess[Network Access Layer];
    NetworkAccess -->|Frames & Bits| Physical[Physical Transmission];
```

### 1. Application Layer

* **Protocols:** HTTP, HTTPS, FTP, SMTP, DNS, DHCP
* Responsible for end-user interactions and data formatting.

### 2. Transport Layer

* **Protocols:** TCP, UDP
* Ensures data delivery, flow control, and error handling.

### 3. Internet Layer

* **Protocols:** IP, ICMP, ARP
* Handles logical addressing (IP addressing) and routing.

### 4. Network Access Layer

* **Protocols:** Ethernet, Wi-Fi, PPP
* Deals with physical transmission of data over cables or wireless channels.

## TCP vs. UDP

| Feature             | TCP (Transmission Control Protocol)   | UDP (User Datagram Protocol) |
| ------------------- | ------------------------------------- | ---------------------------- |
| Connection-Oriented | Yes                                   | No                           |
| Reliability         | High (error checking, retransmission) | Low (no error checking)      |
| Speed               | Slower (due to reliability checks)    | Faster (minimal overhead)    |
| Use Cases           | Web browsing, email, file transfer    | Streaming, gaming, VoIP      |

## IP Addressing

Each device on a network needs a unique identifier, called an **IP Address**. There are two types:

### IPv4

* 32-bit address (e.g., `192.168.1.1`)
* Divided into **Network ID** and **Host ID**
* Uses **subnetting** for efficient addressing

### IPv6

* 128-bit address (e.g., `2001:db8::ff00:42:8329`)
* Designed to replace IPv4 due to exhaustion of addresses

```mermaid theme={null}
graph TD;
    A[IP Addressing] --> B[IPv4];
    A --> C[IPv6];
    B --> D[32-bit Address];
    C --> E[128-bit Address];
```

## Data Encapsulation and Transmission

When data is sent over a network, it passes through different layers, each adding its own header.

```mermaid theme={null}
sequenceDiagram
    participant Application as Application Layer
    participant Transport as Transport Layer
    participant Internet as Internet Layer
    participant Network as Network Access Layer
    Application->>Transport: Adds TCP/UDP Header
    Transport->>Internet: Adds IP Header
    Internet->>Network: Adds MAC Address and Sends Frame
```

## Network Security in TCP/IP

* **Firewalls**: Block unauthorized access
* **Encryption (SSL/TLS)**: Secures data transmission
* **VPNs**: Encrypts network traffic
* **Intrusion Detection Systems (IDS)**: Monitors suspicious activity

## Conclusion

TCP/IP is the backbone of the internet, enabling seamless data communication. Understanding its layers, protocols, and security is crucial for networking professionals.
