This is probably the hardest task when it comes to self-publishing a book with Amazon, Smashwords, B&N, etc. I know it gives me a major headache. The process is so difficult for some that they pay others to do it. The first time I ever formatted a book it took hours. I started at three in the afternoon and was up past midnight. Since then, I am happy to say, it hasn't taken me nearly as long, but every time I start to think I have the process down, new problems crop up. It also doesn't help matters that each place has different things they want, so Amazon wants your cover to be this size and Smashwords wants it another size. Smashwords has a thing that changes your book into several different formats while you wait, but you have to get it ready first. At least there is the awesome Smashwords Guide (for free) to help you on your formatting journey.
Here is my process every single time I have a book ready.
1. Format for Smashwords: I printed out the Smashwords Guide to make things easier on me, and I put it in a binder. So now is the time to crack it open again. I certainly can't remember all the steps. Because programs embed codes into your manuscript, I do the Nuclear Method. This part is simple enough. You copy and paste your entire MS into a program like Notepad to remove codes. Then you copy and paste it into a fresh document on Word. From there I follow the guide, setting style and indents and wiping out extra spaces and other problems. After an hour or two it is ready to upload.
2. Format for Amazon: I use the same document that I already prepared for Smashwords, but I have to turn it into a mobi file, so I use Mobipocket Creator. You can download it for free. It's a great tool. This part doesn't take that long, but I have tiny problems with it each time, just enough to frustrate me to the point of wanting to grab the local employment ads and give up writing for good.
3. Format for Createspace: I use Createspace for print copies. Not because I think they are going to sell well or wind up in my local bookstore, but primarily for me, my family and friends, and a few hardcore fans. Also, they are great giveaways when I want to do a contest. Now my first book Vampires Rule has been picked up by a couple of libraries, so that is awesome. Anyway, back to formatting. This is the MOST difficult part. I use Open Office to make my copy for Createspace. Luckily I found someone online who knows what they're doing and I printed off everything they said to do and put it in the binder with my other formatting guide.
It's kind of cool because you set it on mirror formatting and you get your first look at how your MS will look as a real book. You can do cool things like have a drop letter or a fancy letter at the start of each chapter. I did this for Vampires Rule, but it's difficult so I only did it the one time. Maybe it was twice. Can't remember. There are lots of cool features on this program, but it is a GIANT hassle. Every single time I do it I have a new set of problems and can't figure it out for hours. Last time it was trying to get the page numbers on each page.
Check out what the other carnies have to say about formatting.