codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Subjects
🌐

Computer Networks

26 chapters

1Network Topologies & LAN/WAN2Network Devices (Hub, Switch, Router)3OSI Reference Model4OSI Model & TCP/IP Suite5TCP/IP Protocol Suite6Switching Techniques (Circuit, Packet)7Data Link: Framing & Error Detection8Error Correction (Hamming Code)9Flow Control (Stop-and-Wait, Sliding Window)10MAC: CSMA/CD & CSMA/CA11Network Layer & Routing12IP Addressing (IPv4, IPv6)13Subnetting & CIDR14Routing Algorithms (Distance Vector, Link State)15ARP, ICMP, and NAT16DHCP Protocol17Transport Layer Services18Transport Layer: UDP19Transport Layer: TCP & 3-Way Handshake20TCP Congestion Control21Application Layer: DNS & HTTP22Application Layer: SMTP & FTP23Socket Programming Basics24Wireless Networks & Wi-Fi Standards25VLANs & Spanning Tree Protocol26Network Security & Cryptography
SubjectsComputer Networks

MAC: CSMA/CD & CSMA/CA

Updated 2026-04-22
4 min read

MAC: CSMA/CD & CSMA/CA

The Data Link layer is divided into two sublayers: the Logical Link Control (LLC) sublayer and the Media Access Control (MAC) sublayer.

When multiple computers are connected to the exact same shared communication medium (like an old Ethernet bus cable, or the airwaves in a Wi-Fi network), we have a severe problem. If Computer A and Computer B both transmit electrical signals at the exact same millisecond, those signals will crash into each other on the wire, altering the voltages and destroying the data. This is called a Collision.

The MAC sublayer provides Multiple Access Protocols to determine which device gets control of the shared medium at any given time to minimize or avoid collisions.

1. CSMA (Carrier Sense Multiple Access)

Before transmitting, early networks just sent data blindly (ALOHA protocol), resulting in massive collisions.

To improve this, CSMA introduced a simple rule: "Listen before you talk."

  • Carrier Sense: A node listens to the physical wire to sense if there is a carrier signal (meaning someone else is already transmitting).
  • If the medium is idle, the node transmits.
  • If the medium is busy, the node waits.

The Problem: Because electrical signals take a fraction of a millisecond to travel down a long cable (propagation delay), Computer A might start transmitting, but the signal hasn't reached Computer B yet. Computer B listens, falsely assumes the wire is idle, and starts transmitting. A collision still occurs!

2. CSMA/CD (Collision Detection)

CSMA/CD is the standard protocol used in traditional wired Ethernet networks. It improves upon CSMA by adding a mechanism to detect and recover from collisions.

The Rule: "Listen while you talk."

  1. Listen: The node checks if the wire is idle. If idle, it begins transmitting its frame.
  2. Detect: While transmitting, the node actively monitors the voltage levels on the wire. If the voltage suddenly spikes beyond a normal transmission level, it knows its signal just collided with another signal.
  3. Abort & Jam: The node immediately stops transmitting its data and broadcasts a special Jam Signal to ensure every other node on the network knows a collision just occurred.
  4. Exponential Backoff: The node waits for a random amount of time before trying again. If a second collision occurs, the random wait time is exponentially doubled (to reduce the chance of them colliding a third time).

3. CSMA/CA (Collision Avoidance)

CSMA/CA is the standard protocol used in wireless Wi-Fi networks (802.11).

Why not use CSMA/CD for Wi-Fi? In a wireless network, a radio transmitter is so loud that it drowns out any incoming signals. A Wi-Fi antenna cannot physically "listen" for a collision while it is actively transmitting. Therefore, collisions cannot be detected; they must be avoided entirely.

Furthermore, wireless networks suffer from the Hidden Node Problem. Computer A and Computer C might both be able to reach the central Router B, but a concrete wall prevents A and C from hearing each other. They will both assume the air is clear and transmit simultaneously, colliding at Router B.

The Solution:

  1. DIFS Wait: Before sending, a node listens. If the channel is idle, it must still wait a mandatory period called DIFS (Distributed Inter-Frame Space) before doing anything.
  2. RTS/CTS Handshake (Optional but crucial):
    • The node sends a tiny RTS (Request to Send) frame to the router, essentially asking for permission to speak.
    • If the router is ready, it broadcasts a CTS (Clear to Send) frame to the entire network. This CTS explicitly tells all other computers (even the hidden ones) to shut up for a specific duration.
  3. Transmit: The node finally transmits its data frame.
  4. ACK: Because the sender cannot detect if a collision happened during transmission, it relies on the receiver. The router must send an ACK (Acknowledgment) frame back. If the sender doesn't receive an ACK within a timeout period, it assumes a collision occurred and retransmits.


PreviousFlow Control (Stop-and-Wait, Sliding Window)NextNetwork Layer & Routing

Recommended Gear

Flow Control (Stop-and-Wait, Sliding Window)Network Layer & Routing