Ah, the bad guy; bane of every story's hero(ine). He's the one with all the cards and a penchant for murder and mayhem. He sits in that big, black leather chair, stroking his white cat, devising ever more interesting ways for our hero to die.
Or is he? I'm going to switch to using "antagonist". Antagonist means "opponent, competitor, enemy, rival" and comes from two words - "anti", which means against, and "agonizesthai" which means to contend for a prize. The latter is a very good way to think of your story's bad guy - not so much bad, per say, but in opposition with your hero for a goal.
A well-written antagonist is in himself a rounded character, with aspirations and aims of his own. He should be relatable and, on occasion, sympathetic. That is the reader should understand why he is doing unpleasant things, even as they don't like what he's doing.
Take Rowlings' Snape - the ultimate in sympathetic antagonists. Even though he hates Potter and is in service to Voldemort, his actions are driven by the love he once had for Harry's mother. Snape is also a redemptive antagonist in that, even though he does some pretty nasty stuff, he eventually sacrifices himself in order to save the day.
Thing is, every villain is the hero of his own story. "Good vs evil" tales are very black and white, lacking the subtlety of more intricate ones. Sci fi tends to lean towards this stories. Star Wars is the epitome of "good vs bad", even having a "light" and "dark" side to make it more obvious. And there's nothing wrong with that. Readers/viewers know where they are with such a story.
But if you want a more complex one, then you need an antagonist that you care about. People are never just good or bad, but a mixture of the two. That means your villain needs redemptive qualities as much as your hero needs negative traits. Loki is popular for a reason (beyond the fact Tom Hiddleston is damn cute) and that's because we're made to care about him as a person.