Protagonists and heroes, villains and antagonists; two things that are often considered interchangeable while discussing a story. Your hero is your protagonist and your antagonist is your villain. However in many cases, this isn't true. A hero usually makes a better protagonist than a villain, but not every protagonist is a hero.
A hero is someone like Superman. He is an individual with a high moral code, that is devoted to helping others. He's selfless. He doesn't kill. He believes -and this is the important part- that it is his duty, his responsibility to help others because it's the right thing to do with his powers. As Stan Lee said with Spider-Man, "With great power comes great responsibility". Superman truly believes in his responsibility to his fellow man, and his actions show this. He also doesn't give up his moral code when it would be easier to do so, because it's not right. Heroes always try to do the right thing.
The problem with heroes is that they have to be good. They have to follow their moral code. They're not allowed to deviate from their path, least they not be called heroes anymore. They aren't really allowed shades of gray. To make questionable decisions. We trust them to do the right and good thing and if they don't they loose the title of "Hero".
Villains are like heroes in this respect. They're on the opposite side of heroes though, in morality. They may have an honorable code, but they do things that are considered wrong by the majority of society. Unlike heroes they're completely selfish. They do what they do for personal reasons and damn be the consequences. They may have different reasons for becoming a villain, but in the end they all do it for personal reasons.
Unlike heroes, villains are allowed to do acts of "good" and still be considered villains. This is because the acts of evil often out weigh the acts of good. Yes they may have spared this one person's life but last week they blew up a building killing everyone inside.
One would think then that a hero would be able to do an act of evil every once in a while then. But, people would say, if he did it once, he could do it again and where do you draw the line? Is two evil acts okay, but on your third one you're no longer a hero? The road to the dark side is easy to get on, but more difficult to get off.
Protagonists however, are allowed to have moral shades of gray, as they are just the main view point character. Most of the time they are considered "good" but they are allowed to do evil things, as long as it is not their first resort but instead their last one. They'll kill -but only when in battle for their lives, for example. They don't have a strict code of honor that a hero has, but instead moral guidelines. When they are forced to do an evil act, it effects them negatively. They don't enjoy the fact that they hurt someone, or stole from someone. They can regret it and often do. But they do what they need to do to stay alive and at the same time complete their tasks.
We may watch as a protagonist slow devolves into an "evil" character, but it should be seen as a natural progression of their acts. They become less reluctant to kill, or they no longer feel remorse for the bad things that they've done, for example.
Harry Potter is a good example of a protagonist. He's generally considered good, but he has a moral code. He protects his friends, but doesn't feel the need to protect or be kind to those he doesn't like. The time that he attacked Draco in the bathrooms in The Half Blood Prince, he feels horrified at what he's done, at the pain that he's caused, even though Draco is essentially his enemy. He did not want to hurt Draco as badly as he did, even though he disliked him. He did an evil act, but wishes that he didn't.
On the other hand, Eragon is constantly called a hero -by his author and the people of his world- but he does not show it in his thoughts or actions. He has no code of honor, instead he does what he needs to do to get what he wants done. He willingly kills and tortures those that get in his way, and he delights in his destructive capabilities. He even looks forward to being able to cause violence against his enemies. He does see the use of violence as a last resort or something that he must do to get the job done, but instead as another tool in his arsenal to be used as often as he wants, without care for the consequences.
Antagonists have the most freedom as to what they want to do and how the can act than all the previously mentioned character types. Antagonists are merely someone who opposes the protagonist. They are someone that the protagonist needs to "defeat" to get to their goal. Sometimes the antagonist could be the police, another hero type character, a villain or any number of things. The best sort of antagonists are the ones that have their own motivations and reasons for doing things, for opposing the protagonists. They may be actively trying to stop the protagonists or their paths just happen to be at cross measures. Antagonists can be the most mysterious characters in a story because we don't know why they're doing what they're doing and why they're opposing the protagonists. An antagonist could easily become the protagonist, if we were telling the story from their point of view.
Because of this, antagonists should never just oppose the protagonist "just because". They need to have their own reasons and motivations for doing things. An antagonist who opposes the protagonist "just because" is there because the story demands that there be something in the way of the protagonist getting what he wants easier. He has no reasons or motivation. We know that he's going to block the protagonist's way because that's what he's supposed to do, and that makes him uninteresting. We know that he's going to lose, because he has nothing at stake, no reason for him to need to win. He's not a true challenge for the protagonist.
A good antagonist should make the protagonist work for their victory. He should have an equal chance of winning. This leaves the reader in constant wondering on how exactly is the victory going to be pulled off. How is the protagonist going to defeat the antagonist? At what cost shall there be victory? I think the best example of this sort of reasoning comes in, once again, the Half Blood Prince. In the first chapter, Fudge is talking to the Muggle Prime Minister about the war that has started between the wizards and Lord Voldemort. The Prime Minister, finally says, "But you're wizards! You can do magic! Why can't you stop all of this?" And Fudge tells the Prime Minster, "The problem is, the other side can too."