Why/how does shaving work (i.e. cuts hair but not skin)?

When I was first learning to shave my legs, I cut myself plenty. Give a thirteen year old a safety razor and you’ll see.