The main use of the twenty sided die in Dungeons and Dragons is to determine whether something does or does not happen. A d20 roll would determine the answer to these questions:
- I shoot my bow at the dragon. Do I hit it?
- I try to scale the wall of the castle. Do I climb it successfully?
- The vampire tries to charm me. Do I resist the effect and retain my wits?
Now, there is a bit of nuance beyond simply using the d20 to answer yes/no questions. Each of these three examples represents one of the three different types of rolls you will make with your d20: attack rolls, ability checks and saving throws.
So, what's the difference between these three types of rolls? They apply in different circumstances.
Attack rolls are the easiest to understand. You make an attack roll when you are trying to physically hurt someone else. Trying to stab a goblin with a dagger? Attack roll. Trying to shoot a giant spider with a crossbow? Attack roll.
Some spells spells also require you to make an attack roll to see if you hit. The spell will say if that's the case. If the spell doesn't mention an attack roll, then the spell automatically hits.
Ability checks are when your character is trying to accomplish a goal. Trying to push over a statue? Athletics check. Trying to follow the tracks of an owlbear? Survival check. Trying to stabilize a fallen comrade? Medicine check. Trying to threaten information out of someone? Intimidation check.
Saving throws are when your character is trying to avoid a negative consequence. The negative consequence could be any number of things. Perhaps you've accidentally set off a trap, and you're trying to avoid getting caught in its steel jaws. Perhaps a medusa tried to turn you to stone, and you're trying to resist the effect. Perhaps you're walking through a desert and you're trying to resist the exhaustion of not having enough water. Perhaps you are mortally wounded, and you're trying to stave off death itself.
In each of these situations, you're trying to avoid something. Each of these will call for a saving throw.
For many spells that do not require attack rolls, instead, the target of the spell will have to make a saving throw. Spells that have an area of effect tend to work this way. Just like with attack rolls, the spell will explain who needs to make what kind of saving throw.