There is old advice for writing that says "A villain is the hero of their own story." I used to think this was one of those 'always true' things, but my thoughts on it have grown nuance. At the surface level essentially it just means that from the villain's perspective they are the good guy trying to do a thing, and that is fair. However, there is room for villains to be good villains that break that.
As with everything there is variance, there are exceptions, and there is wiggle room to be found - especially when it comes to how you define terms. Which means, to go forward I need to define a term and for the purpose of this the term in question is "Hero."
Hero: Noun. The key character in a story or arc responsible for solving a problem or bringing about some change.
Not a great definition to catch all the nuances of the word, but it works for the purposes of this.
Frodo Baggins is a hero as he is the key character responsible for 'solving the problem' of the One Ring and bringing about the end of Sauron in the Lord of the Rings.
Luke Skywalker is a hero as he is the(a) key character responsible for solving the problem of Anakin Skywalker's fall to the dark side, the rise of Darth Vader, and the downfall of Emperor Palpatine.
But it doesn't have to be that large of a scale.
Edmond Dantes of the Count of Monte Cristo is the hero of that story, the key character who solves the problem of the injustice inflicted upon him by his jealous friend.
And with that, we have the makings for a workable villain. So let's begin.
First We Need A Problem
With this vein of building a villain you start with the problem. This is the motivation for the villain. This is the thing they are trying to solve. The goal they are trying to accomplish. In defining this problem you need to define if it is personal or societal. Magneto is trying to solve the societal problem of the oppression and genocide of Mutants, which he likens to the oppression and attempted genocide of the Jewish people under Nazi Germany. Palpatine on the other hand is trying to solve the personal problem that there is a galaxy out there suffering under the great injustice of not having him in charge of it.
Second You Need The Core Of The Villain
This is who the villain is as a person. Palpatine is a politician from the paradise like world of Naboo. He is educated and politically savvy. He has ambition. The fun part about this step is you can make the villain as an actual Hero here. Give them flaws if you want, but focus on the good aspects of who they are. What makes them uniquely qualified to solve this problem?
Third You Need To Know How Far The Villain Will Go
And this is where villainy comes in. When it comes to Villains being the Heroes of their own story, the key difference between a Hero and a Villain is how far they're willing to go to accomplish their goals. Heroes are willing to sacrifice themselves for their goal. Self sacrifice in this regard is heroic. Villains though? Villains go a step further. Villains will sacrifice others. Some villains will sacrifice everything.
Look at Palpatine, his ambition for power is so great he masters the dark side of the force, starts a galaxy wide civil war, raises and trains several apprentices with the sole goal of sacrificing them like pawns to get him even more power. This is a man who would throw the galaxy into a black hole rather than allow someone less capable than he of running it as they see fit.
Vader, by contrast, struggles with this. Make no mistake, Vader is a monster, but he is not as willing to sacrifice everything for it. That struggle, the fact there are things he can't sacrifice, are the key to his downfall.
Fourth, You Need To Figure Out How This Villain Solves Their Problem
You have a problem, you have a villain, and you have their limits. Now you need to figure out how that villain, within the confines of their limits and abilities, goes about solving that problem.
Magneto uses his powers as a mutant to bring the fight directly against the human oppressors he sees. He uses these actions to build a following that he uses to strike out in protest, and to prepare for the war he knows is coming.
Palpatine plays politics, a spider in his web, manipulating events from the shadows to push him ever onward and upward to his goal.
Edmond Dantes uses his new found wealth, training, and strategic thinking to set up situations and scenarios that move his targets into place for when he gets to finally have his revenge.
Fifth, You Need To Figure Out How Far Along They Are When We Meet Them
This is important for GMing games and telling stories in particular. The villain often has a headstart on the heroes because villains tend to be more pro-active while heroes are reactive. So how far along is the villain in their plot when we meet them? For a weaker villain, put them earlier in their arc. Palpatine as an apprentice just learning Sith Powers is a much easier foe than Emperor Palpatine, Sith Lord.
This is also how you can line up multiple villains. The further along they are to their goal, the stronger they tend to be because they've built up. Smaller villains can be earlier on, but knowing the plot for them means you know how they'll develop if left unchecked. Stronger villains are further along, but having that plot means you know their roots and where they came from.