Andy Weir didn't sell The Martian to a publisher first. He posted it free on his own website, chapter by chapter, and let readers stress-test the science before it was ever a book. That backwards path is a big part of why the novel feels so airtight.

The Direct Answer
He self-published it serially on his blog, then as a 99-cent Kindle book, before Crown bought it.
Weir started posting The Martian free, one chapter at a time, around 2009, and readers, many of them scientists, checked his math as he went, per his own account in Advice to Writers and elsewhere.

He Published It Free, One Chapter at a Time

Weir began writing The Martian in 2009. He'd shopped earlier novels to literary agents and gotten nowhere, so this time he skipped them and put the story straight on his website, one chapter at a time, for anyone to read at no cost. His audience skewed technical. A lot of them were engineers and scientists who treated each new chapter like something to fact-check.

That's where his day job showed up in the work. Weir had spent years as a software engineer, and he handled the book's hardest science the way he'd handle a coding problem. His research ran wide, from orbital mechanics and the history of human spaceflight to conditions on the Martian surface and even botany. To map the Hermes spacecraft's route between Earth and Mars, he wrote a program to run the numbers instead of guessing at them.

I wrote my own software to calculate constant-acceleration orbital trajectories so I could define the path Hermes took to get from Earth to Mars.

Andy Weir, guest essay on John Scalzi's Whatever

Readers caught things he missed. When someone with a chemistry background flagged a problem, he'd revise the posted chapter and keep going. The famous hydrazine sequence, where the stranded astronaut pulls water out of leftover rocket fuel, went through that kind of scrutiny before most people ever read it.


From a 99-Cent Ebook to a Crown Deal

Some readers asked Weir to post a Kindle version because it was easier to download than clicking through chapters on a webpage. He agreed and set the price to the lowest number Amazon would let him charge, 99 cents. The ebook climbed to the top of Amazon's science-fiction list and sold roughly 35,000 copies in three months, more than had downloaded the free version.

That traction pulled in the publishing industry he'd bypassed. Podium picked up the audiobook rights in January 2013, and Crown bought the print rights that March for a reported six figures, bringing the novel to shelves in 2014. For the wider picture of how he works, see the full Andy Weir writing routine.

What You Can Steal