A three second violation in basketball is a rule that says that a player cannot stay inside the paint for more than 3 consecutive seconds.
There are two different types of three second violations, those called on defense and those called on offense. An offensive three second violation is called by referees when a player whose team is in control of the ball stays in the paint for longer than 3 seconds without trying to actively score. In a defensive three second violation a player cannot stay for three consecutive seconds inside the paint if not guarding an offensive player. The count starts when a player's foot first enters the area, and it ends when both feet are out of it. A player's feet must completely leave the paint before they can re-enter, lifting feet into the air and jumping do not count as leaving the paint. The count resets when that player leaves the paint.
The three second violation rules are the reason why players that are near the key are constantly moving around the court both on offense and defense. If a player is careless and ends up committing the violation, the referee will blow the whistle and bring his arm forward with 3 fingers showing to signal that there was a three-second violation. If the mistake is made while the player's team is on offense, the ball will be turned over to the opponent. If the violation called is a defensive one, a technical foul is awarded to the team, leading to a free throw attempt by the opponent plus the subsequent possession of the ball.
There are two types of 3-second violations in basketball:
The goal of the three second rule pertaining to the offense is to keep offensive players from spending too much time just standing under the net. If they were allowed to stay below the net for the entire time that the shot clock runs, it would be way easier to get rebounds, block out defenders, and score. This rule challenges the offensive to keep moving and be more creative with how they score and get rebounds.
The purpose of the three second violation for the defense is very similar to that of the offense. If defensive players were able to stand within the key for the whole shot clock time, they would be able to better knock away shots, get rebounds, and defend the basket. This rule and threat of violation ensures that the offense has more chances of getting to the basket, but also requires the defense to be more efficient in the way they defend outside of the key.