The penalty situation, also known as the bonus, is a situation where a team will get additional free throws on every foul committed by the other team. The rules for the penalty are different in different leagues, so let's break it down and understand it.
In both college and professional basketball, every personal foul is also counted as a team foul. A team's total number of fouls determines whether the opponent is considered in the bonus. The number resets to 0 every half or quarter. Once a team's amount of fouls reaches the number required for the bonus, every foul after this will result in free throws, even if it's not a shooting foul. This means you can commit a common foul and it will result in free throws for the other team, as long as you have the required amount of fouls.
In college basketball, there are two levels to the bonus. The first, just called the bonus, is reached when a team commits 7 team fouls. Every foul after the 6th team foul in a half (up until 10 team fouls) will result in a one and one. This means that a player gets a possible 2 free throws, but will only get to shoot the second free throw if they make the first one. After 2nd shot, the ball is live if the player misses. The second level of the penalty situation in college basketball is called the double bonus. Every foul after the 10th team foul in a half will result in 2 free throws, no matter whether the player makes or misses the first free throw.
The NBA has much different rules for the bonus. If a team reaches 5 fouls in a quarter, the other team is now in the bonus. They will get 2 free throws for every foul committed after this point. There is no one and one, it's just always 2 shots. If a game is in the last 2 minutes of regulation or overtime, then 2 fouls will put a team in the bonus. This is to let teams foul to get possession of the ball back, even if they have not committed enough fouls throughout the quarter.
REMEMBER: In college basketball, two 20 minute halves are played in a game, and in the NBA, four 12 minute quarters are played in a game.
There are some strategies that surround being in the penalty situation. Towards the end of a game, a team may try and intentionally foul the other team to get possession back. The way this works is simple. A team that is losing will foul if they have committed enough fouls to be in the penalty situation, giving the other team free throws and thus getting possession back after.