The answers by William and Brandon were very accurate. I just wanted to outline the basic publishing process since you asked how a book gets published after writing it. To make it as uncomplicated as possible, the following assumes the author wants to get the book published by a publisher instead of self-publishing.
1. For a nonfiction book, a book proposal is often submitted by the author to either an agent or an editor at a publisher. This proposal contains a book outline, discusses competitive titles and marketing, describes the author’s credentials and includes one or two sample chapters. This usually happens even before the author submits the entire book, also known as the manuscript. For fiction, the book proposal is replaced by a synopsis of the novel, which is basically an outline of the book, accompanied by a few chapters. Unless the author has been previously published or is very well known, a book proposal or a synopsis will need to be submitted before an agent or editor accepts a complete manuscript.
2. If an agent is interested in the book, the author will be asked to submit a complete manuscript. Then the agent decides whether or not they want to represent the book. If so, they ask the author to sign a contract and then approach editors at publishers. Larger publishers only work with authors who are represented by agents. Smaller publishers usually will accept manuscripts directly from authors.
3. If a publisher wants to publish the book, several things happen after a contract is signed. Typically, an editor is assigned to work with the author to revise the manuscript, which almost always is needed. Then the book goes through a production process, which involves copy editing, permissions for any sources or artwork that may be used, page layout, typesetting, page proofing, cover design and creation and physical print production. Nowadays, major books are often produced in print, eBook and audiobook formats. EBooks require special formatting. Audiobooks require selecting a narrator and sometimes music as well.
4. Well before the book is actually published, the publisher launches a marketing campaign first to the trade (booksellers, reviewers and media) and then to the public. This may involve ads and author appearances as well as other promotions. The book is made available via one or more distributors to book selling outlets, including bookstores and online booksellers.
I hope this description of the basic publishing process is helpful to you.
My industry experience began before the Internet, when a writer had two publication options: 1). Traditional, where the writer must create a query letter (no longer than 1-2 pages) to hook the attention of a publishing house's acquisitions editor, or 2). Vanity (known today as Self-Publishing), where all production costs are paid by the writer. While publishing a novel is different than publishing a nonfiction book, both start with a clear, coherent idea.
Today there's a third option: Hybrid, where the writer pays 50%, and the publisher covers the other half. The difference between Hybrid and Self-Publishing (as on Amazon, and with Vanity presses) is that Hybrid publishers maintain quality standards, employing professional editors. The benefit (and hazard!) of Vanity/Self-Publishing is that anyone can publish a book—no matter how poorly written, because there's no editorial oversight. This doesn't mean Self-Publishing should be dismissed—hardly. It's most useful for producing books with very specialized subject matter lacking mass appeal: How to Grow Hot Peppers Indoors, or Restoring Vintage Toy Trains.
Traditional (New York City—and elsewhere) publishing remains the most difficult to achieve, but certainly isn't impossible. The writer must first learn the craft by reading, reading, and reading . . . writing, writing, and writing. As with becoming a doctor/surgeon, there are no "secrets" or shortcuts to success.
The one absolute necessity is an undeniable love for writing, exploring existence, and sharing what you've discovered with others.