Infinitely Fallible

Notes on Computer Networks

A computer network is created when two or more computers share data in some way. The most famous computer network (the Internet) is composed of tens of billions of devices connected via a lot of networking infrastructure (routers, switches, etc.). The Internet can be modeled as having 5 core layers.

The Five Layer Internet Protocol Stack

Layer Name Description Protocols / Hardware
Layer 5: Application The interface users interact with to send/receive messages. It handles high-level data exchange. DNS, SMTP, HTTP, BitTorrent
Layer 4: Transport Breaks data into segments. Ensures they arrive in the correct order without errors. TCP, UDP
Layer 3: Network Moves datagrams between hosts (routing) using IP addresses (IPv4/IPv6). Determines the best physical path. IP, ICMP, OSPF, Routers
Layer 2: Data Link Encapsulates datagrams into frames. Moves data between nodes on the same network using MAC addresses. 802.11 (Wi-Fi), Ethernet, Switches
Layer 1: Physical The actual hardware level. Transmits raw bit streams (1s and 0s) over physical media. Ethernet cables, Fiber optics, Radio waves

Encapsulation

How do the layers and protocols that run on each layer communicate with each other?


Network encapsulation
Subsequent layers on the Internet encapsulate the layers above it.

Layers receive messages from the layer above it. Once a message is received by a given layer, a layer specific header is appended to that message. For example, the transport layer receives a message (M) from the application layer and appends a header (TLH) to the message it receives. This creates a segment which is an application layer message with a transport layer header appended to it. We say a segment encapsulates the application layer message.

If we move down a layer then we see that the network layer appends its own header (HN) to a segment thus creating a datagram. The HN includes information about the source and destination addresses of the end hosts.

At each layer the message is a combination of two parts:

  1. the payload, which is the message from the layer above
  2. the new appended header information.

At the receiving end this process is reversed with headers being stripped off at each layer which is called de-encapsulation.

Routers and layer 2 switches do not implement all the layers of the protocol stack. Routers implement layers 1-3 and layer 2 switches just implement layers 1 and 2. End-hosts implement all five layers while the intermediate hosts do not. This is an intentional design choice known as the end-to-end principle. This keeps the core of the Internet simple while pushing complexity to edges.

The Transport and Application Layers

TCP/UDP