I've written NINE technical books and worked with multiple publishers. I've also done indie publishing.
People like to ask questions about that, so here's a thread on lessons I've learned
Writing books probably won't be especially profitable.
Unless you're selling hundreds or books yourself or tens of thousands through a publisher.
Here is how royalties typically work:
1) You get an advance. Let's say $5000 2) The royalty rate is typically around 10% 3) Royalties must pay off the advance before you get them 4) If the book costs $30 then your royalty per sale is $3 (0.1 * 30)