For a long time California was part of Mexico, first under Spanish rule and then in 1821 fell under Mexican rule. John Freemont established the Republic of California in 1848 and then gold was discovered in 1849. By 1850, enough people had flocked to California that it was ceded to the United States and in 1850 California became the 31st State in the Union.
The first census was taken in 1850.