If there's a story equation, it looks something like this: Person plus Desire minus Obstacle = story. Desire is the easy part, as we all yearn for something or other. It's defined by your story world, what it dangles to pull your protagonist along, be it revenge, romance, adventure, materialism, belonging, and so on. Regardless of genre, there's a pitfall equation: Dull Person = Who Cares? Fortunately, the menu for assembling a compelling character is as big as the Dallas phone book.
Why do we care?
Gamers know the fun of assigning traits to a character and then piloting him through the game world. Reading is similar. We watch the person grow, tsk at his mistakes, emphasize with his joy and misery, judge his oppressors. It's a vicarious way to satisfy the need for adventure, and a good yarn will even teach you a few things, depending on the author's area of expertise.
Where do we get ideas?
Life experience is a good way to make a character authoritative on some subject you've studied or practiced. Books, movies, TV, and games have a way of resonating through scenes that reach you at a personal level. People you know are a great resource, but should be confined to speech and personality; their mark on the story is up to you, and they'll be called on to react in ways they probably wouldn't in real life. Fictional characters are often built around a single trait. Seinfeld gave us the eccentric Kramer, shallow Jerry, and insecure George.
Maximize the impact by tailoring these to create the biggest driving force. In fantasy, a low-born person who yearns for forbidden knowledge might be unexpectedly virtuous. Can he or she handle it without being corrupted? Naturally, the elites will oppose it, and you can even through in some Inquisition types to up the danger level. Let's not forget villains. They'll seek to exploit fears and insecurities, pit their strengths against those of the protagonist. He'll either grow or suffer a setback. There's also the matter of too much of a good thing, like generosity and curiosity, recipes for exploitation.
Is there a magic formula?
Not really. The more universal the appeal, the more people can identify with your hero. Most writers have a personal vision for the protagonist to fulfill. It often leads them to a niche market, which can be more satisfying than taking a shotgun blast at the market with a clone of Superman or Harry Potter. Genre is a good place to start. In a squalid city of thieves, your guy must be stealthy, streetwise, a fighter, and able to rationalize breaking the law. He's also a stickler for the clan code of honor; it's a good idea to create a situation that requires him to go against it.
That's the basic idea, and a good way to hone skills is by doing fan fiction. Established characters leave you free to practice prose, description, and dialog. It works, being tested by experience.