Avoiding pregnancy

How do people go years without getting pregnant or having pregnancy scares? I’m not nervous to have sex but I’m nervous about getting pregnant