Before the Model S, Tesla was producing the Roadster in a garage in Menlo Park, Cali, individually putting the cars together one by one. In 2009, Tesla only made 800 of the electric sports cars. With the company looking to expand exponentially, Elon came across a factory run by GM and Toyota that was 5.5 million square feet and had a plastics molding factory, two paint facilities, 1.5 miles of assembly lines, and a 50-megawatt power plant. About 450,000 cars were being produced at that plant per year at the time. But a plant that size was far more costly than anything his budget allowed for.
Initially Musk wasn't even allowed to visit the factory in Fremont, but in 2010, GM pulled out of the plant after having to declare bankruptcy, and Toyota planned to shut down production. Interest in the massive building was low, so Musk was able to get away with way lower than what the facility was actually worth.
He's since also purchased 35 acres adjacent to the factory for a test track and is currently looking into building a lithium ion battery megafactory with production "comparable to all lithium ion production in the world.”