{
    "slug": "tcp_ip_model",
    "term": "TCP/IP Model",
    "category": "networking",
    "difficulty": "intermediate",
    "short": "The four-layer model (Link, Internet, Transport, Application) that describes how data is packaged, routed, and delivered across the internet.",
    "long": "The TCP/IP model layers from bottom to top: Link (Ethernet, WiFi — physical transmission), Internet (IP — addressing and routing between networks), Transport (TCP/UDP — end-to-end delivery), Application (HTTP, DNS, SMTP — what applications speak). Each layer adds a header encapsulating the layer above. Understanding TCP/IP explains why HTTP needs TCP (reliable), why UDP suits video (fast, loss-tolerant), and why IP routing works across heterogeneous networks.",
    "aliases": [
        "network stack",
        "OSI model",
        "internet protocol suite"
    ],
    "tags": [
        "networking",
        "fundamentals",
        "protocols"
    ],
    "misconception": "The OSI 7-layer model is how the internet actually works — TCP/IP's 4-layer model is the practical implementation; OSI is a conceptual reference model.",
    "why_it_matters": "Understanding TCP/IP explains connection timeouts, why HTTPS adds TLS between TCP and HTTP, and how tools like tcpdump and Wireshark capture traffic at different layers.",
    "common_mistakes": [
        "Confusing TCP (reliable, ordered, connection-oriented) with UDP (unreliable, unordered, connectionless).",
        "Not understanding that IP addresses are Layer 3 (Internet) and MAC addresses are Layer 2 (Link) — they serve different scopes.",
        "Assuming HTTP requires TCP — HTTP/3 uses QUIC over UDP for improved performance.",
        "Not accounting for TCP connection overhead — each new TCP connection requires a 3-way handshake adding round-trip latency."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "http_status_codes",
        "tls_handshake",
        "websocket_protocol",
        "http2",
        "dns_resolution"
    ],
    "prerequisites": [
        "http_request_response_cycle",
        "dns_resolution",
        "network_latency_bandwidth"
    ],
    "refs": [
        "https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview"
    ],
    "bad_code": "# Ignoring TCP connection cost — new connection per request:\n# PHP script making 100 HTTP calls with new connections each time:\nfor ($i = 0; $i < 100; $i++) {\n    $ch = curl_init($url);\n    curl_exec($ch);\n    curl_close($ch); // Connection closed — 100 TCP handshakes\n}",
    "good_code": "# Reuse connections with persistent handles:\n$mh = curl_multi_init();\n$handles = [];\nfor ($i = 0; $i < 100; $i++) {\n    $ch = curl_init($url);\n    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); // HTTP/2 multiplexing\n    $handles[] = $ch;\n    curl_multi_add_handle($mh, $ch);\n}\n// HTTP/2 multiplexes all 100 requests over one TCP connection",
    "quick_fix": "Understand the stack: Application (HTTP) → Transport (TCP) → Internet (IP) → Link (Ethernet) — PHP operates at the Application layer; TCP connection reuse via keep-alive reduces per-request overhead",
    "severity": "info",
    "effort": "medium",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/tcp_ip_model",
        "html_url": "https://codeclaritylab.com/glossary/tcp_ip_model",
        "json_url": "https://codeclaritylab.com/glossary/tcp_ip_model.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[TCP/IP Model](https://codeclaritylab.com/glossary/tcp_ip_model) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/tcp_ip_model"
            }
        }
    }
}