One of the hardest things in writing is deciding who you’re writing for. A pat answer is to write for yourself, and that’s perfectly valid, but every writer wants to be read more broadly than that. But trying to write for a broad audience is probably always a trap. Andy Weir, the author of the Martian, describes in an interview how he wound up with both:
I had about 3,000 regular readers that I’d accumulated over 10 years of writing fiction and web comics and stuff like that. I was really writing it for them. I didn’t have market appeal in mind when I was writing the book. I was thinking, I have 3,000 hardcore nerds that are my readers, because I’m a hardcore nerd, and I’m going to write a story that they’ll enjoy. So that’s why it was pretty heavy on the math and the science and the show-your-work kind of stuff, because that’s exactly what my readers like. I had no idea that it would end up being popular in the mainstream, and still to this day I don’t know what I did right. I don’t know how this story that was basically a prolonged math problem ended up getting so popular among people who aren’t that interested in math!
I love his confession of not knowing what he did right. Whatever he did to appeal to a broad audience is nearly impossible to pin down, but I’d say that what he did right was knowing his audience and writing for them unapologetically. The rest was just gravy.