A traffic stop normally ends with a citation—the annoyed motorist simply drives away. But an officer will sometimes prolong a traffic detention, in the process searching the driver's vehicle.
In some instances, an officer who has stopped a vehicle has a legal justification for searching it. Other times, that justification doesn't exist. For example, if an officer doesn't witness any apparent traffic violation or have any other objective basis for pulling a car over in the first place, any evidence that turns up from a car search will probably be inadmissible in court.
Even when there's a lawful basis for a traffic stop, an officer who issues you a citation can't search you or your car without a basis to suspect that you are armed and dangerous or involved in criminal activity (other than the minor traffic violation).
A 2018 U.S. Supreme Court case—about unauthorized rental car drivers—illustrates the principle that the police can't search a car just because they've stopped it. The practical rule from that case is that police may not search a rental car after a traffic stop based only on the fact that the person driving isn't on the rental agreement. Someone who has permission to use a car from the person who rented the car doesn't lose all Fourth Amendment rights merely by not being on the rental agreement. (Byrd v. U.S., 138 S.Ct. 1518 (2018).)
Despite the rule above, there are plenty of circumstances where officers can search cars they've stopped. Laws in many states authorize police officers to arrest drivers for minor traffic offenses, such as speeding or failure to wear a seatbelt. In these and other arrest situations, the validity of a subsequent search depends on the circumstances.
After arresting an occupant, the police typically may search the passenger compartment of a vehicle if it reasonably appears that the arrestee might access the vehicle during the search or that the vehicle contains:
The ensuing search must be limited to areas that might contain the items the searching officer reasonably expects to find.
If, for example, officers have arrested a motorist for driving on a suspended license, handcuffed him, and placed him in a locked patrol car, they don't have a lawful basis to search the car. The driver isn't able to access the car at the time of the search, nor can the officers reasonably expect to find evidence of the crime for which they arrested him: driving on a suspended license. (Arizona v. Gant, 556 U.S. 332 (2009).)
Even without an arrest, an officer who sees, hears, or smells something suspicious during a traffic stop can probably search the car. And if the police conduct a traffic stop and arrest and frisk the driver, and thereby find contraband, they can likely move on to search the vehicle.
Further, police officers can often search cars after arrest pursuant to the inventory search exception.
In addition, when they don't or aren't sure they have a legal basis for a search, officers often use the driver's consent as a basis to search. (It's perhaps easier in theory than in practice to say "no" to a police officer.)
If you face criminal charges, regardless of whether they stem from a car search, consult an experienced criminal defense attorney. An attorney who knows the law in your jurisdiction will be able to explain the relevant rules, including any exceptions to the general principles discussed in this article.