Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / Networking 1: Addresses and Routing

    The Local Network: MAC Addresses, Ethernet, Wi-Fi, Switches

    A group of devices that can reach each other directly, without passing through a router, is a

    Chapter 3 of 115 min read

    The Plain Picture#

    In one office building, everyone has a badge number printed on their ID card by the company that made the card. When you want to hand a paper to a colleague in the same building, you just shout their badge number and walk it over.

    Badge numbers are useless outside the building — nobody in another city cares. For that, you need a postal address (the next chapter).

    The Real Names#

    • A group of devices that can reach each other directly, without passing through a router, is a local area network (LAN) — your home Wi-Fi, or one office floor.

    • Every network card (the chip that connects a device to a network — Wi-Fi or cable) has a MAC address: a 48-bit number written as 6 hex bytes, like a4:83:e7:1b:2c:9f. It's set by the manufacturer (the first 3 bytes identify the manufacturer). MAC stands for Media Access Control.

    • Ethernet is the standard for wired LANs; Wi-Fi is the standard for wireless LANs. Both use MAC addresses.

    • At this layer a packet is called a frame.

    • A switch is a box with many cable sockets that connects devices in a LAN. It learns which MAC address is on which socket and forwards each frame only to the right one. (Your home Wi-Fi router contains a small switch plus a wireless access point plus a router — three boxes in one.)

    Under the Hood#

    How a switch learns:

                          SWITCH
                ┌─────────────────────────┐
      laptop ── │ port 1                  │
      aa:aa:... │                         │     MAC table the switch builds:
      printer ─ │ port 2                  │       aa:aa:...  →  port 1
      bb:bb:... │                         │       bb:bb:...  →  port 2
      phone ─── │ port 3                  │       cc:cc:...  →  port 3
      cc:cc:... └─────────────────────────┘
    1. When a frame arrives on port 1 from aa:aa:…, the switch writes down "aa:aa:… lives on port 1".

    2. To forward a frame to bb:bb:…, it looks up its table and sends it only out of port 2.

    3. If it doesn't know the destination yet, it sends the frame out of every port (flooding) and learns from the reply.

    Broadcast: the special MAC address ff:ff:ff:ff:ff:ff means "everyone on this LAN". A switch sends broadcast frames to every port. Chapters 8 and 9 use broadcasts.

    See your MAC address: on your Mac, ifconfig en0 | grep ether (Wi-Fi is usually en0). On Linux, ip link.

    Gotchas

    • MAC addresses never leave the LAN. When a packet crosses a router (Chapter 7), the link-layer envelope is thrown away and a new one is made with new MAC addresses for the next hop. Only the IP addresses stay the same end to end.

    • MAC addresses aren't reliable identities. They can be changed in software, and phones now use a random MAC per Wi-Fi network for privacy.

    Check yourself

    4 questions
    1

    What is a LAN?

    Show answer

    A group of devices that can reach each other directly without a router.

    2

    How long is a MAC address, and how is it written?

    Show answer

    48 bits, written as 6 hex bytes separated by colons.

    3

    How does a switch know which port to send a frame to?

    Show answer

    It learns the source MAC of every frame it receives and which port it came in on; it floods only when it doesn't know yet.

    4

    Does a packet from your laptop to a server in Mumbai keep the same MAC addresses the whole way?

    Show answer

    No. MAC addresses are only for one local hop; each router replaces the link-layer header. The IP addresses stay the same.