For spell to hit and DC... it gets complicated.
There is a 'to hit' effect for some spells. This is your chance to hit the target with a projectile and do damage. Some spells auto hit, like magic missile or the spells that give you a radius effect. An example of a spells that needs to roll to hit would be a firebolt cantrip. Those spells have you roll an attack against the enemy's armor class using your bonuses to hit for spells. Here are the relevant considerations for those abilities:
1. 1d20 for to hit base, plus
2. Bonuses from effects on your character, such as 'bless' adding a 1d4 (or 2d4) to hit chance.
3. Bonus for your character's proficiency. All player characters start with a +2 proficiency score, get to +3 at level 5, and then to +4 at level 9.
4. Bonus for your spellcasting proficiency bonus. If you are a wizard casting the spell your would use your intelligence bonus, which is calculated as (Intelligence / 2) - 5, rounded down. So if you have 12 int you get +1, 16 int +3, etc.
5. Bonuses or penalties for to hit advantage (sleeping target, held target, stunned target, casting from outside range, casting from below, casting from above, gain advantage or disadvantage from many many other sources).
For spellcasting DC (difficulty class) you are using your value against what the enemy rolls to determine if they can avoid damage, or overcome an effect.
Your spellcasting DC base is 8 + proficiency bonus + spellcasting proficiency bonus (dependent on which stat you used to cast the spell), and may also get some other bonuses from items or effects.
The proficiency bonus is dependent on level, as explained above.
The spellcasting proficiency bonus is also calculated as above.
Your opponent is trying to roll to overcome your spell save DC. The spell will tell you which stat the enemy is rolling with (dex save, wis save, etc.) and the enemy is rolling a d20
So if you are a level 6 warlock and your opponent is trying to avoid damage from your fireball (dex save for half damage), you have 20 charisma, and your opponent has 12 dexterity, here is what the calculation looks like.
Your spell DC is 8(base) + 3 (level based proficiency bonus) + 5 (charisma spellcasting bonus) = 16.
Your opponent will roll a D20 and get his saving throw bonus from dexterity (same formula as spellcasting proficiency bonus) of +1, and if he is proficient in dexterity saving throws he will add his level based proficiency total to his roll as well, plus any items/effects/etc that may effect him.
Let's say he is proficient in dexterity saving throws. He is also level 6, so he gets +3 based on level.
Your opponent will roll D20 +1 (dex bonus) + 3 (level based proficiency bonus), and has to beat or tie your 16 to reduce the damage.
This can make magical items that give you proficiency in saving throws very valuable. It can also make magical items that give a bonus to your spell DC temporarily or permanently extremely powerful. I have a hat that increases my spellcasting DC by two each time I inflict damage with a fire spell. So I can cast scorching ray, which lets me target three enemies separately for a ray of fire damage, and get a +6 spellcasting DC bonus from the hat (that decreases each turn). With my buffed up DC I can usually hold person and expect it to stick.