JSTAcademy
0 XP
Dashboard
Networks & OS
TCP/IP & Network Fundamentals
14 min
Masters+150 XP
Networks & OS · Masters

TCP/IP & Network Fundamentals

How data travels across the internet — protocols, layers, and addressing
14 min read+150 XP on completionCert: Networks & Operating Systems
Tap any word in the text below to start reading from there.

TCP/IP & Network Fundamentals

Every web request, database query, API call, and real-time update travels over a network. Understanding how that happens — the protocols, the layers, and the mechanics — is foundational for every software engineer who builds systems that communicate.

The OSI Model

The OSI model conceptually divides network communication into 7 layers:

Layer 7 - Application: user-facing protocols — HTTP, FTP, SMTP, DNS, WebSocket. The data your application creates and consumes.

Layer 6 - Presentation: data encoding and encryption — TLS operates here (though it spans 5-7 in practice), character encoding (UTF-8), compression.

Layer 5 - Session: managing session state between communicating parties. Largely absorbed into application protocols in modern systems.

Layer 4 - Transport: end-to-end communication — TCP (reliable, ordered), UDP (fast, unreliable). Port numbers live here — they identify which application on a host should receive data.

Layer 3 - Network: logical addressing and routing — IP addresses, routers. Packets (IP packets) travel from source to destination, potentially through many routers.

Layer 2 - Data Link: node-to-node communication on a local network segment — MAC addresses, Ethernet, WiFi. Frames travel between devices on the same network.

Layer 1 - Physical: electrical signals, optical signals, radio waves. The actual bits on the wire.

How encapsulation works: application data becomes a segment (TCP adds port, sequence number) → packet (IP adds source/destination addresses) → frame (Ethernet adds MAC addresses, CRC) → bits on wire. At the destination, each layer strips its header and passes data up.

IP Addressing

IPv4 uses 32-bit addresses written as four octets: 192.168.1.100. With only 4.3 billion possible addresses, IPv4 address exhaustion drove the need for NAT (Network Address Translation) — private address ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) used in homes and offices, with a single public IP shared by many devices.

IPv6 uses 128-bit addresses written in hex: 2001:0db8:85a3::8a2e:0370:7334. The address space is vast enough to give every atom on Earth an address.

CIDR notation: 192.168.1.0/24 means the first 24 bits (192.168.1) are the network, the last 8 bits are hosts. /24 gives 254 usable hosts; /16 gives 65,534; /8 gives 16,777,214.

Routing: a router maintains a routing table mapping destination networks to next-hop addresses. When a packet arrives, the router finds the most specific matching route and forwards the packet to the next hop.

TCP: Reliable Delivery

TCP provides reliable, ordered, connection-oriented communication:

Connection establishment (three-way handshake):

  1. Client sends SYN with Initial Sequence Number (ISN_C)
  2. Server responds with SYN-ACK: acknowledges client's ISN and provides its own ISN_S
  3. Client sends ACK: acknowledges server's ISN

Both sides now have agreed-upon sequence numbers for tracking which bytes have been delivered.

Sequence numbers: every byte sent has a sequence number. The receiver acknowledges bytes received. If an acknowledgment isn't received within a timeout, the sender retransmits. This guarantees every byte arrives exactly once, in order.

Flow control (sliding window): the receiver advertises how much buffer space it has. The sender won't send faster than the receiver can consume. Prevents overwhelming a slow receiver.

Congestion control: TCP infers network congestion from packet loss and adjusts its sending rate. Algorithms: slow start, AIMD (Additive Increase Multiplicative Decrease), CUBIC, BBR. This is why a file transfer slows when a network is congested.

Connection teardown: FIN-ACK → ACK → FIN-ACK → ACK (four-way handshake). TIME_WAIT ensures any delayed packets are absorbed before the port is reused.

UDP: Speed Over Reliability

UDP adds nothing to IP except source/destination ports and a checksum. No connection, no acknowledgment, no ordering guarantees.

Use cases:

  • DNS: one small request, one small response. Retrying is cheap; TCP overhead isn't worth it.
  • Video streaming / WebRTC: a late video frame is worthless; better to drop it and show the next one than to wait for retransmission.
  • Gaming: game state updates happen so frequently that a missed packet is less harmful than the latency of TCP's retransmission.
  • QUIC (HTTP/3): UDP-based protocol implementing its own reliability and multiplexing — avoids TCP's head-of-line blocking.

DNS: The Internet's Phone Book

DNS (Domain Name System) translates human-readable hostnames (jsupremetech.online) to IP addresses (104.21.33.211).

Resolution chain:

  1. Browser cache
  2. OS cache / /etc/hosts
  3. Recursive resolver (your ISP or 8.8.8.8)
  4. Root nameserver (knows TLD servers)
  5. TLD nameserver (.online knows the authoritative server for jsupremetech.online)
  6. Authoritative nameserver → returns the IP

DNS record types:

  • A: hostname → IPv4 address
  • AAAA: hostname → IPv6 address
  • CNAME: alias → another hostname
  • MX: mail server for domain
  • TXT: arbitrary text (used for SPF, DKIM, site verification)
  • NS: nameserver for domain

TTL (Time To Live) controls caching. Short TTL (60s) enables fast failover; long TTL (86400s) reduces DNS lookup overhead.

HTTP/HTTPS Protocol

HTTP is an application-layer protocol over TCP. Key elements:

Request: method (GET, POST, PUT, DELETE, etc.), URL, headers (Host, Content-Type, Authorization, etc.), optional body.

Response: status code (200 OK, 404 Not Found, 500 Internal Server Error), headers, body.

HTTP/1.1 vs HTTP/2 vs HTTP/3:

  • HTTP/1.1: one request per connection at a time (keep-alive allows reuse but not parallelism); head-of-line blocking
  • HTTP/2: multiplexing — many requests in parallel over one TCP connection; header compression (HPACK); server push
  • HTTP/3 (QUIC): UDP-based; eliminates TCP head-of-line blocking; faster connection establishment; built-in encryption

HTTPS = HTTP + TLS: TLS (Transport Layer Security) provides encryption, authentication (certificates), and integrity. The TLS handshake happens after TCP connection and before HTTP requests.

0%