惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
博客园 - 【当耐特】
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
MyScale Blog
MyScale Blog
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hugging Face - Blog
Hugging Face - Blog
I
InfoQ
B
Blog RSS Feed
腾讯CDC
云风的 BLOG
云风的 BLOG
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
雷峰网
雷峰网
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
DataBreaches.Net
The Cloudflare Blog
V
V2EX
S
SegmentFault 最新的问题

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I Finally Understood Routers and Switches by Connecting T...
TAKUMI SUGAT · 2026-05-08 · via DEV Community

TAKUMI SUGATA

Introduction

While studying for CompTIA Network+, I couldn't totally grasp the difference between routers and switches. Even when I memorized their functions, the knowledge never stuck. However, once I knew the reason why they are needed, everything clicked. So, I decided to write it down.


Understand the difference between routers and switches

Comparing these two devices side by side makes it much easier to understand.

Switch:
 → Transfer data inside the same network
 → Use MAC address
 → Layer 2(Data Link Layer)

Router:
 → Transfer data in different networks
 → Use IP Address
 → Layer 3(Network Layer)

Enter fullscreen mode Exit fullscreen mode

Familiar example

Switch = extension call in the office
 → Connect with people from the same company

Router = international telephone exchange
 → Connects people from different countries (networks)
 → Determines which route to use

Enter fullscreen mode Exit fullscreen mode

Division of roles of routers and switches

              Internet
               │
     ┌────────────┴──────────┐
     │      Router           │ ← Layer 3
     │ Different NW Transfer │ Judge from IP address
     └────────────┬──────────┘
               │
     ┌────────────┴─────────────┐
     │            Switch         │ ← Layer 2
     │ The same NW Transfer      │ Judging from MAC address
     └───────┬──────────┬────────┘
           │        │
          ┌──┴──┐    ┌──┴──┐
          │PC-A │    │PC-B │
          └─────┘    └─────┘

Enter fullscreen mode Exit fullscreen mode


The main role of routers

1. Routing ( Route Selection )

It decides routes that head to the destination.

Tokyo → Osaka:
  Route A: Tokyo → Nagoya → Osaka
 Route B: Tokyo → Kyoto → Osaka
  ↓
 Choose the best path for data transfer  

Enter fullscreen mode Exit fullscreen mode

2. Network segmentation・ border

The router acts as the boundary between the Internet and the internal network.

         Internet
         │
         │ Global IP
         │ 203.0.113.1
     ┌──────┴──────┐
     │   Router    │
     └──────┬──────┘
         │ Private IP
         │ 192.168.1.1
     ┌──────┴──────┐
     │   Switch    │
     └──┬───────┬──┘
       │     │
     ┌──┴──┐ ┌──┴──┐
     │PC-A │ │PC-B │
     │~.1.2│ │~.1.3│
     └─────┘ └─────┘

Enter fullscreen mode Exit fullscreen mode

3. NAT ( Network Address Translation)

NAT is a mechanism that allows multiple devices to share a single global IP address.

【NAT( Sharing one IP address by multiple PCs)】

Internal Network (Office)        Internet
┌───────────────────┐            ┌───────────────┐
│ PC-A 192.168.1.2  │            │               │
│ PC-B 192.168.1.3  ├── Router ──┤  203.0.113.1  │
│ PC-C 192.168.1.4  │            │  (Just one) │
└───────────────────┘            └───────────────┘
Multiplex private IPs            1 Global IP

Enter fullscreen mode Exit fullscreen mode

4. Data flow

【PC-A → Data flow to the Internet】

PC-A(192.168.1.2)
 ↓ " I need to send this to the Internet"
Switch
 ↓ head to Router
Router
 ↓ exchange to global IP(NAT)
 ↓ select the best path
Internet
 ↓
Destination server

Enter fullscreen mode Exit fullscreen mode

5. Packet filtering


A basic security feature that blocks unauthorized access 
from outside the network.

Enter fullscreen mode Exit fullscreen mode


Routing Table

Routers have maps called routing table.
They look at it and select the path for destinations.

Destination network  | Next router      | Distance
192.168.1.0/24  | Direct connection        | 0
10.0.0.0/8      | 192.168.2.1     | 1
0.0.0.0/0       | 203.0.113.1     | Default

Enter fullscreen mode Exit fullscreen mode


Static routing and Dynamic routing

Static routing

It is a method to configure the routing tables by hand.

Administrator
 ↓ Configure the route by hand
Router A ──→ Router B ──→ Router C
               ↓
             Destination NW

Static route → If you need change, you have to update it by hand as well

Enter fullscreen mode Exit fullscreen mode

Features:
・For small scale network
・Best suited for environments where routes rarely change 
・Simple settings
・Gives administrators full control over routing decisions

Enter fullscreen mode Exit fullscreen mode

Dynamic routing

It is a method to configure the routing tables automatically.

Router A ←→ Router B ←→ Router C
 ↕      ↕      ↕
Exchange routing information each other 
Choose the best path automatically 
Handle automatically, if routes change

Enter fullscreen mode Exit fullscreen mode

Features:
・For large scale network
・Best suited for environments where routes change frequently
・Handle automatically, if routes change
・Protocols: RIP・OSPF・BGP etc…

Enter fullscreen mode Exit fullscreen mode

Proper use

Static Routing  → Small scale and the least update environment
Dynamic Routing → Large scale and frequent update environment

Enter fullscreen mode Exit fullscreen mode


Links with OSI reference model

Layer 7  Application  │
Layer 6  Presentation │
Layer 5  Session      │  Not applicable for routers
Layer 4  Transport    │
─────────────────────────────
Layer 3  Network      ← Router function (IP Address)
─────────────────────────────
Layer 2  Data Link    ← Switch function (MAC Address)
Layer 1  Physical     ← Cable・ Physical signal
─────────────────────────────

Enter fullscreen mode Exit fullscreen mode

Familiar example for routers

A home Wi-Fi router is actually an all-in-one device that combines a router, a switch, and a Wi-Fi access point.

Domestic Wi-Fi Router
┌─────────────────────────────────────────────────────────────────┐
│ Router function→ Connect between domestic network and Internet  │
│ Switch function→ Connect PC with wired connection               │
│ Wi-Fi AP function→ Connect devices with wireless connection     │          
└─────────────────────────────────────────────────────────────────┘
       ↕
       Internet

Enter fullscreen mode Exit fullscreen mode


Summary

Router = Devices that transfer data between different networks

Main role:
 → Routing( Selection for the best route)
 → Border for network
 → NAT( Sharing one IP by multiple PCs)
 → Packet filtering

The difference of Router and Switch:
 Router → Layer 3・IP address・ Between different NWs
 Switch → Layer 2・MAC address・ Between same NWs

Routing kinds:
 Static  → manual・ for small scale
 Dynamic → automatic・ for large scale

OSI Layer: Layer 3(Network Layer)

Enter fullscreen mode Exit fullscreen mode


Conclusion

When I started to study for them, I couldn't remember each functions of these devices.
Once I connected each function to a familiar real-world example, everything fell into place. Understanding the difference between routers and switches makes these types of questions much easier to handle.