Computer Networks

Foundations Of Networking

What a Network Is and Why Layers

Get a message from a program on YOUR machine to

JrCodex·6 min read

Jr Codex Computer Networks Notes

Level: Beginner Prerequisites: None Time to complete: ~15 minutes


Table of Contents

  1. The Problem
  2. What Goes Wrong Without Structure
  3. Layering
  4. What a Protocol Is
  5. The Two Rules of a Good Layer
  6. Summary & Next Steps

1. The Problem

The Task
─────────────────────────────────────────
  Get a message from a program on YOUR machine to
  a program on a machine you have never seen,
  possibly on another continent, over equipment
  owned by a dozen companies you have no
  relationship with.

  The message must arrive complete, uncorrupted, in
  order, addressed to the right PROGRAM on the
  right MACHINE — and it must work whether the
  first hop is wifi, fibre, or a mobile network.
─────────────────────────────────────────

That is genuinely hard, and every layer in this curriculum is one piece of the answer.


2. What Goes Wrong Without Structure

Imagine solving it in one program, end to end.

The Concerns You Would Have to Handle
─────────────────────────────────────────
  - turning bits into voltages, light pulses or
    radio waves
  - detecting that a bit flipped in transit
  - finding which of billions of machines is the
    destination
  - choosing a route through networks you do not
    control
  - retransmitting what was lost
  - reordering what arrived out of sequence
  - slowing down when the network is congested
  - encrypting so nobody in between can read it
  - and finally, the actual message
─────────────────────────────────────────
Why One Program Cannot Work
─────────────────────────────────────────
  COMBINATORIAL EXPLOSION
    Every application would need code for every
    physical medium. Email over wifi, email over
    fibre, email over 5G, web over wifi... N
    applications × M media = N×M implementations.

  NO INTEROPERABILITY
    Two machines could only communicate if they ran
    the same program.

  NOTHING COULD CHANGE
    A new physical medium would require rewriting
    every application.

  With layers: N + M implementations, and either
  side can be replaced independently.
─────────────────────────────────────────

3. Layering

The Idea
─────────────────────────────────────────
  Split the problem into layers. Each layer:

    - solves ONE class of problem
    - USES the layer below through a defined
      interface
    - PROVIDES a service to the layer above
    - does not know or care HOW the layer below
      works
─────────────────────────────────────────
The Chain of Consequences
─────────────────────────────────────────
  A physical wire moves bits, and sometimes
  corrupts them.
      ▼ so...
  The DATA LINK layer adds framing and error
  detection, giving reliable delivery to the NEXT
  MACHINE.
      ▼ but that only reaches one hop, so...
  The NETWORK layer adds global addressing and
  routing, so a packet can cross many hops.
      ▼ but packets can be lost, duplicated or
        reordered, so...
  The TRANSPORT layer adds reliability, ordering
  and flow control between PROGRAMS.
      ▼ now we have a reliable byte stream, so...
  The APPLICATION layer defines what the bytes MEAN
  — a web request, an email, a query.
─────────────────────────────────────────
Read That Chain Again
─────────────────────────────────────────
  Each layer exists because of a limitation of the
  one below it. That is the whole structure, and it
  is why this curriculum is ordered bottom-up.

  When you meet a new protocol, ask: "what
  limitation of the layer below does this address?"
  The answer is usually its entire reason for
  existing.
─────────────────────────────────────────

4. What a Protocol Is

The Definition
─────────────────────────────────────────
  A PROTOCOL is an agreement between two parties
  about how to communicate. It specifies:

    SYNTAX     the format of messages — which bits
               mean what, in what order
    SEMANTICS  what each message MEANS, and what
               the receiver should do
    TIMING     when messages may be sent, how long
               to wait, what to do on silence
─────────────────────────────────────────
A Protocol You Already Know
─────────────────────────────────────────
  Answering a telephone.

    SYNTAX     "Hello?" — a recognisable opening
    SEMANTICS  it means "I am here, go ahead"
    TIMING     if nobody speaks for ten seconds,
               hang up

  Both parties must follow it. One side saying
  nothing, or speaking a different language, and
  the exchange fails — regardless of how good the
  connection is.
─────────────────────────────────────────
Horizontal and Vertical
─────────────────────────────────────────
  Layer 4 on your machine talks to LAYER 4 on the
  server. Logically horizontal — as though they had
  a direct line.

  Physically, the message goes DOWN your stack,
  across the wire, and UP theirs.

     YOUR MACHINE            THEIR MACHINE
     Application  ◄─ logical ─►  Application
     Transport    ◄─ logical ─►  Transport
     Network      ◄─ logical ─►  Network
     Link         ◄─ logical ─►  Link
        │                            ▲
        └──── the ACTUAL path ───────┘

  Each layer is written as though it talks directly
  to its peer. That illusion is what makes layers
  independently implementable.
─────────────────────────────────────────

5. The Two Rules of a Good Layer

RULE 1 — HIDE WHAT IS BELOW
─────────────────────────────────────────
  A web browser contains no code about radio
  frequencies, fibre optics, or Ethernet framing.

  It asks for "a reliable connection to this host"
  and gets one. Whether that runs over wifi in a
  café or fibre in a datacentre is invisible.

  This is why the same browser works on every
  network ever invented, including ones built after
  it shipped.
RULE 2 — DO NOT DUPLICATE WHAT IS BELOW
─────────────────────────────────────────
  If the link layer already detects corruption, the
  transport layer should not re-implement the same
  check for the same reason.

  Some duplication IS deliberate — TCP checksums
  end-to-end even though links check hop-by-hop,
  because a router could corrupt data in memory
  between the two checks. This is the END-TO-END
  PRINCIPLE, and Module 4 develops it.

  The rule is: duplicate only when the layers
  guarantee genuinely different things.
─────────────────────────────────────────
Where Layering Leaks
─────────────────────────────────────────
  The model is a simplification, and it shows:

  - TCP performance depends heavily on the physical
    medium (Module 4, Chapter 5) — wifi loss looks
    like congestion, and TCP slows down wrongly
  - NAT (Module 3, Chapter 5) inspects transport
    headers from the network layer
  - HTTPS spans several layers at once

  Layering is a very good approximation, not a law.
  Knowing where it leaks is part of knowing it.
─────────────────────────────────────────

6. Summary & Next Steps

Key Takeaways

  • Without layering, every application would need an implementation for every physical medium, giving N×M code paths and no interoperability.
  • Each layer exists because of a specific limitation of the layer below it, which is why the layers form a chain of consequences rather than an arbitrary list.
  • A protocol specifies syntax, semantics and timing, and both parties must follow it for communication to succeed.
  • A good layer hides what is below it and avoids duplicating it — except where the guarantees genuinely differ, as with end-to-end checksums.

Concept Check

  1. Why does layering turn N×M implementations into N+M?
  2. State the limitation of the physical layer that the data link layer exists to address, and the limitation of the data link layer that the network layer addresses.
  3. Give an example of layering "leaking", and say why it happens.

Next Chapter

Chapter 2: The OSI and TCP/IP Models


Jr Codex — 1-on-1 Personalized Coaching | Back to Module Index | Back to Computer Networks Index