The business of insurance is called underwriting. The company enters into a contract (called a policy) and agrees to indemnify a group of people like you against defined losses. So it uses some heavy duty math to work out the probability of the losses being incurred. It's called risk assessment and relies on a complicated use of statistics. For vehicle insurance, the companies collect the details from every reported traffic accident in the US looking at the age, sex and occupation of the driver, the make and model being driven, the time of day, the road conditions, and the extent of the damage. The insurers share the information on the current costs of replacement parts and the labor to fit them.
They also manage to talk the health insurance companies into sharing their current costs on medical treatment for those injured in traffic accidents. With all this information, they can make good estimates of the cost of loss, i.e. the total amount they may have to pay out if they insure, say, 100,000 drivers. They take this estimate, add the cost of running the insurance company and a profit margin. This total is then divided between all the 100,000 as their premiums. Some companies divide the total equally so the good drivers subsidize the bad. But the majority adjusts the individual amounts based on the driver's safety record. That way, each policy holder pays more or less depending on how well he or she drives. This is more fair.
But, to cut costs, some insurance companies make more general assumptions about the likelihood of losses. Instead of personalising the risk assessment, they focus the assessment on generalities. The most common is the use of the zip code. In some areas of a town or city, there are higher levels of vehicle theft and vandalism. Some areas have more people driving while intoxicated or impaired through drugs. Because of the design of the local road system, there may also be a higher number of accidents. The insurers therefore charge everyone living in those areas a higher premium. Apart from the unfairness at an individual level, some lawyers believe it is active discrimination because many of the zip code areas loaded with higher premiums have higher concentrations of particular racial or ethnic groups. California has formally prohibited insurance companies from using zip codes, credit scores and other factors not directly relevant to the assessment of driver safety. In those states, insurers continue to trade and make a profit. It has not been the end of the world they predicted.
So, depending on the US state in which you live, your premium may either be calculated based on your personal driving record, or it may be based on your zip code and credit score. Either way, the task of finding the cheapest car insurance remains the same. You have to shop around the companies licensed to sell policies in your state and find the best deal. If there is active competition between the insurers, the premiums will be lower and you will find the cheapest car insurance without too much difficulty. But if the state is unregulated and insurers do not compete, it will be more difficult to find a cheap policy.