Well, in the NBA, there’s the theory and the practice for fouls of course.
There are fouls and violations. Offensive violations include travelling, a three-seconds in the lane violation, and a few others. The penalty is that the other team gets the ball. Defensively, the only real violation is three seconds in the lane (without guarding anyone) and the penalty is a single free throw for the other team (and they get the ball back after the free throw).
For fouls, the system in the NBA is that if a player is fouled in the act of shooting, they get the basket and and extra free throw if the basket is made. If the player missed, they get two free throws (or three if the player was attempting a three-point shot).
If the player is not shooting, then for the first five fouls on a particular team in each quarter, the fouled team gets the ball out of bounds. For the sixth and subsequent non-shooting fouls, the fouled player gets two free throws.
Referees can decide a particular foul is particularly dangerous or egregious and call it a flagrant foul, for which there are a couple of different levels of seriousness and associated extra penalties which I’m not going to bother looking up right now. There’s also a special case, similar to a flagrant foul, where fouling a player in front of you on a fast break can be given extra penalties, but I’m not looking that up right now either.
Finally, there are technical fouls, which the referees can call for things like cursing, objecting too strenuously to the referee or throwing the ball to indicate displeasure. Technical fouls result in a single free throw for the other team, and play restarting with an in-bounds to whoever had the ball.
Additionally, a player with six personal fouls or two technicals is out of the game.
Fouls are used strategically in three situations: First, if a player has a wide open chance at a basket, and a defender can foul him to prevent the basket, it’s usually considered a good move to give two free throws rather than a guaranteed basket. Though the defender runs the risk of allowing a three point play (if the person scores), running up his own foul total too high, or getting called for a flagrant, so it’s not an automatic decision.
Second, near the end of a quarter, if a team has committed less than five fouls, the ‘have a foul to give’ and will foul to prevent even a slight chance at scoring, since if they foul before a shot attempt, they’re not really giving up anything. Finally, as time starts running out at the end of a game, the team that’s ahead will try to just hold the ball to run down the clock. The team that’s behind may intentionally foul just to get the ball back (after the other team’s free throws).
Now, then there’s your other question about the practice of foul calling in the NBA. There’s three parts to the answer: first is that referees are only human, and NBA players are incredibly quick, and referees just miss things and make mistakes; secondly, and related to that, things happen so quickly in the NBA that referees often have to make assumptions about what happened, so the guy with a reputation for fouling a lot will often get more fouls called. Finally, that process has evolved to where it’s widely acknowledged that the biggest stars in the NBA do get calls that rookies and less famous players don’t.