Skip to content
Dev Dump

Network Fundamentals

Every internet-connected device receives an IP address to identify it on the network.

IP Address Types

Format: a.b.c.d where each octet is 0–255 (e.g., 192.168.1.100)

AddressPurpose
127.0.0.1Loopback (localhost)
0.0.0.0All interfaces / unspecified
255.255.255.255Broadcast
TypeDescriptionExample
Public IPAccessible from internet, globally uniqueAWS EC2 public IP, your home router’s WAN IP
Private IPInside local network only, not routable on internet10.0.0.5, 192.168.1.100
RangeCIDR# of AddressesCommon Use
10.0.0.010.255.255.255/8~16.7 millionLarge enterprises, cloud VPCs
172.16.0.0172.31.255.255/12~1 millionMedium networks
192.168.0.0192.168.255.255/16~65,000Home networks, small offices
  • 128-bit addresses (vs 32-bit IPv4)
  • Format: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
  • Expands address space massively; design principles remain similar

Subnetting divides a network into smaller, manageable segments. CIDR (Classless Inter-Domain Routing) notation makes this precise.

Subnetting Overview

10.0.0.0/16
│ │
│ └── Network bits (16 bits fixed for network)
└── Base IP address
CIDRNetwork BitsHost Bits# of Hosts
/882416,777,214
/16161665,534
/24248254
/2828414
/323201 (single host)
VPC: 10.0.0.0/16 (65,536 IPs)
├── Public Subnet: 10.0.1.0/24 (256 IPs)
├── Private Subnet: 10.0.2.0/24 (256 IPs)
└── Database Subnet: 10.0.3.0/24 (256 IPs)

Ports distinguish different services running on the same host.

Ports and Sockets

RangeNameDescription
0–1023Well-known/SystemReserved for standard protocols
1024–49151RegisteredAssigned by IANA for specific services
49152–65535Dynamic/EphemeralUsed by clients for temporary connections
PortProtocolService
22TCPSSH
53UDP/TCPDNS
80TCPHTTP
443TCPHTTPS
3306TCPMySQL
5432TCPPostgreSQL
6379TCPRedis
27017TCPMongoDB

A socket is an endpoint for communication: (IP Address, Port)

Client Socket: 192.168.1.100:54321
│ │
│ └── Ephemeral port
└── Client IP
Server Socket: 10.0.1.50:443
│ │
│ └── Well-known port (HTTPS)
└── Server IP

TCP vs UDP

  • Reliable: Guarantees delivery with acknowledgments
  • Ordered: Data arrives in sequence
  • Connection-oriented: 3-way handshake before data transfer
Client Server
│ │
│── SYN ──────────▶│
│◀────── SYN-ACK ──│
│── ACK ──────────▶│
│ │
│◀═══ Data Flow ═══▶│

Use cases: HTTP/HTTPS, SSH, email, file transfer

  • Unreliable: No delivery guarantee
  • Unordered: Packets may arrive out of sequence
  • Connectionless: No handshake, just send

Use cases: Video streaming, online gaming, DNS queries, VoIP

FeatureTCPUDP
ReliabilityGuaranteedBest-effort
OrderingYesNo
SpeedSlower (overhead)Faster
Use caseData integrity criticalReal-time, loss-tolerant

TLS (Transport Layer Security) sits above TCP to provide:

  • Encryption: Data is unreadable to eavesdroppers
  • Authentication: Server (and optionally client) identity verified
  • Integrity: Data tampering is detected

DNS translates human-readable domain names to IP addresses.

Browser DNS Resolver Root/TLD/Auth DNS
│ │ │
│── "google.com" ───────▶│ │
│ │── Query ──────────────▶│
│ │◀── "142.250.185.78" ───│
│◀── "142.250.185.78" ───│ │
TypePurposeExample
AIPv4 addressgoogle.com → 142.250.185.78
AAAAIPv6 addressgoogle.com → 2607:f8b0:4004:...
CNAMEAlias to another domainwww.google.com → google.com
MXMail servergmail.com → alt1.gmail-smtp-in.l.google.com
TXTText data (SPF, verification)v=spf1 include:_spf.google.com ~all
NSName servergoogle.com → ns1.google.com

The OSI (Open Systems Interconnection) model explains how data travels from your application to another computer across the network. Think of it as 7 steps your data goes through.

OSI Model

When you send data (e.g., open google.com):

  1. Your browser creates the request (Layer 7 - Application)
  2. Data gets encrypted with HTTPS (Layer 6 - Presentation)
  3. A session/connection is established (Layer 5 - Session)
  4. Data is split into segments with port numbers (Layer 4 - Transport)
  5. Segments get IP addresses added (Layer 3 - Network)
  6. Frames are created with MAC addresses (Layer 2 - Data Link)
  7. Converted to electrical/radio signals (Layer 1 - Physical)

When receiving: The process reverses (Layer 1 → 7)

LayerNameWhat It DoesReal Example
7ApplicationThe actual app/service you useChrome browser, email client
6PresentationEncrypts, compresses, formats dataHTTPS encryption, JPEG compression
5SessionStarts, maintains, ends connectionsStaying logged into Netflix
4TransportEnsures delivery, assigns portsTCP ensures no data loss, port 443
3NetworkRoutes packets across networksYour IP address, router decisions
2Data LinkHandles local network deliveryYour laptop’s MAC address, switch
1PhysicalActual cables and signalsEthernet cable, WiFi radio waves

Remember the layers (7 to 1) with: “All People Seem To Need Data Processing”

  • Application
  • Presentation
  • Session
  • Transport
  • Network
  • Data Link
  • Physical
LayerSystem Design Relevance
Layer 7Application load balancers (ALB), API gateways, WAF
Layer 4Network load balancers (NLB), faster but less flexible
Layer 3VPC routing, subnets, security groups

ConceptKey Points
Public IPGlobally unique, internet accessible
Private IPLocal only, uses RFC 1918 ranges
CIDR/16 = 65K IPs, /24 = 256 IPs
Ports0-1023 system, 1024-65535 user
TCPReliable, ordered, connection-oriented
UDPFast, unreliable, connectionless
DNSTranslates domains to IPs