A context switch is the kernel saving the currently running thread's CPU state (registers, program counter, stack pointer) and restoring another thread's, so a single core can multiplex many threads. It happens on every scheduler preemption, blocking syscall, or interrupt — and it isn't free.
Where the cost hides
DIRECT cost (visible, ~1–5 µs):
save/restore registers · run scheduler logic · switch kernel stacks
if PROCESS switch: also swap page tables (CR3) → FLUSHES the TLB
INDIRECT cost (often much larger):
cold CPU CACHES → the new thread's data isn't in L1/L2/L3 → cache misses to RAM
cold TLB → address translations must be re-walked
lost pipeline / branch-predictor state
