Depending on the situation and type of foul in basketball, the penalty will be different. Non-shooting fouls generally cause the team to lose possession of the ball. Shooting fouls result in free throws. If the basket was made when the player was fouled, then the basket counts and one free throw is awarded. If the basket wasn't made, then either two free throws or three (if the player was attempting a three point shot when fouled) are awarded.
Player shooting a free throw
Source: US Navy
Fouling Out
Each time a player commits a foul, they get another personal foul added to their name. If they reach a certain total during they game they will have "fouled out" and will not be allowed to play any more. It takes five fouls to foul out in college and high school, six fouls in the NBA.
Team Fouls
The total number of team fouls add up during the game as well. After a certain number of fouls, a team is considered "over the limit" and free throws will be awarded for non-shooting fouls. The rules for the NBA and college/high school are different:
NBA - Team fouls are added up per quarter. Four fouls are allowed with two free throws being awarded starting with the fifth foul. Only defensive fouls count toward team fouls.
NCAA college and High School - Team fouls are added up per half. After 6 fouls a team is awarded a one-and-one free throw. A one-and-one means that the first free throw must be made in order to get a second free throw. If the player misses the first, the ball is live and play begins. After 10 fouls in a half, two free throws are awarded.
Technical Foul
A technical foul is given for unsportsmanlike conduct or other infraction. This can range from fighting to arguing with the official. Both coaches and players can get technical fouls.
In high school the penalty for a technical foul is two free throws and the ball for the other team. Also, if a player or coach receives two technicals during a game, they will be ejected. In college a technical foul counts as a personal foul as well, so it adds into fouling out. In the NBA a technical foul does not count as a personal foul.
Flagrant Foul
Another type of foul in basketball is the flagrant foul. This is when a foul could seriously injure an opponent. Generally two free throws and possession of the ball are awarded. In high school and college the player committing the flagrant foul is ejected from the game. In the NBA it can count as a technical foul or the player can be ejected depending on the severity of the foul.