One thing that's always resonated with me is a quote I heard a while back, can't remember where. "Every villain is the hero of their own story." Now you can replace hero with antihero, badass, whatever, but the point is that almost no one sees the things they do as wrong. Or at least, not wrong without purpose. It could be that their morals are twisted or absent, that they have a compulsion to do certain things, or even that they realise they're doing unsavory things but they justify it as necessary to do a greater good(as they see it).
This has honestly helped me write NPCs a lot better. Sphinx made a great summary with his post above about basic motivations, priorities, etc, and for me the most basic question is "What does this guy/girl want, and how do they want to get it?". A street thug in a gang probably only really knows how to get what they want through violence, so for them every problem can be solved the same way. That's why they make great basic bad guys. You don't need to feel bad for shooting the guy that just wants to rob/kill/etc everyone.
For other bad or evil NPCS, take a look at TV, movies, and even real world examples and then try to see how they view whatever they're doing as the "right":thing, or see themselves as the hero.
The gang leader? He's seen his friends, family, etc get killed, turn to drugs, sex trade, or worse. He's been hurt and stepped on, so he'll do whatever it takes to not get hurt again, and to show the world how tough he is. As long as people show him the respect he thinks he deserves, they're good. Doesn't mean he won't crack a few skulls to make sure people know though.
Organised Crime? Nearly every single group here has some group they respect and care about, and a code of ethics to operate by. The Mafia and the Yakuza, for example, entrench themselves deeply in the communities they operate in, to the point that they're sometimes seen as more benevolent and helpful than the government. The Italian mob rose to power largely by taking care of local businesses and peoe in their community and being less corrupt than a lot of the police and government officials. Sure they charge for "protection", but on some level they tried to keep business and family separate, and boy did they respect family. And the Yakuza are no strangers to helping out communities ether. In the relatively recent floods in Japan, it was the Yaks that made sure food, supplies, and aid in trucks got through to help a bunch of communities that were suffering afterwards. Seriously, Google it, it's really neat to read about. Do they commit violence, horrible crimes, etc? Sure. But they try to be as civil as possible about most of their business.
Honestly some of the most "evil" people are those who use the system to achieve positions of immense power. How many government leaders and corporate CEOs are there that have done unspeakable things in the name of power and profit? As Gordon Gekko once said, "Greed us good", and boy do they believe it. Their main motivation is to constantly acquire and keep as much power and wealth as possible. Why? Because it gives you freedom. Freedom to say yes or no, to do what you want, to get what you want, and to stop the other guy from saying you can't do or have something. What they're willing to do for this varies widely, but on some level their morals tend to usually be sone version of "The ends justify the means". After all, when you make the rules, who can tell you they're wrong?
Anyway this was much longer than expected, but always try to figure out why an NPC believes they're right , and it'll help a lot.