California’s population is approaching 40 million after growing by nearly 300,000 people during the year ending July 1, 2017, state officials reported Thursday in their annual county-by-county population update.

That puts the state’s total population at 39.6 million, by far the largest in the country.

Thirteen counties shrank, most of them sparsely populated areas in far Northern California and the Sierra Nevada range. Marin County lost 161 people, for a total population of 262,545.

California’s counties range in size from 10.3 million in Los Angeles, which is larger than most states, to tiny Alpine with just 1,141 people — nine fewer than a year ago.

Most of the population growth came from births, which outpaced deaths by 220,000. More people moved out of California than in from other U.S. states, but foreign immigration made up the difference. Total net migration added 80,000 people, according to the report by the Department of Finance.

The largest numeric increases were in the Southern California counties of Los Angeles, Riverside, San Diego, Orange and San Bernardino, which each grew by more than 20,000 people. The biggest percentage jumps were in the Sacramento suburbs, the Inland Empire outside Los Angeles and the Central Valley.

Nine counties with more than 1 million people each comprise 70 percent of the state’s population. They include the cities and suburbs of Los Angeles, San Diego and Sacramento as well as Silicon Valley and the East Bay outside San Francisco.

With 880,000 people, San Francisco is the state’s 12th largest county.