Your publisher advances you roughly the amount they think the book will make in royalties, and then they pay for the editing, the formatting, the printing, some promo, etc. They have in-house teams of marketers and publicists who will at LEAST pitch your book to libraries, retailers, etc.