What are the rules around challenge ratings for magic users and spell?

I know that different types of creature have there own challenge ratings and that different versions of the same creature also have. But what are the rules around determining NPC enemy magic user challenge ratings and do the spells I equip them with impact that rating. For instance a level 4 sorceror armed with damage causing spells vs the same sorceror with a more varied spell list some of which won’t be relevant in the combat?

I am looking for Either any specific guidelines or rules that are provided. Or proven “Home brew” rules DMs use consistently.