I've used a scrap of fabric and some embroidery floss to illustrate this tutorial but you can use the same technique to add button loops to knitting. If your yarn splits easily you can use a few of the plys to work the loops. If you're using a fuzzier yarn like wool it's probably better to use a matching colour of embroidery floss.
Step 1: Thread your needle and use a few stitches worked on top of each other to anchor the thread to the wrong side of your work, pull it through to the front at the point where you want the loop to begin.
Step 2: Loop the thread over your finger, or a knitting needle, or anything that will give a loop big enough to fit your button through. I usually just use trial and error to get the loop the right size, make sure it's right at this stage. It gets much easier with practice to judge how big your loop needs to be for a particular button size.
Step 3: At the point where you want the loop to end bring the thread back through to the wrong side and out through the first hole.
Step 4: Repeat steps 2 and 3 a couple more times, so that your loop is made up of 3 strands which will make your button loop sturdier.
Step 5: With the work held in your left hand bring the thread up and over your left index finger and through the loop from bottom to top.
Step 6: Bring the needle through the loop of thread caught on your finger from front to back.
Step 7: Remove your finger.
Step 8: Pull the thread tight, sliding the stitch you've just made up against the fabric. You've completed the first buttonhole stitch.
Repeat steps 5 to 8 to work more buttonhole stitches around the loop.
Continue until the whole loop has been stitched over, making sure that it is snugly filled. Fasten off the thread on the wrong side with a few stitches worked on top of each other.
Instead of working your button loops right on the edge you might want to work them set in a little. This picture shows the loop worked on the right side.
And this one shows the loop worked on the wrong side of the cloth so that only a bit of it peeks out from the edge. Both ways are equally functional but give a slightly different look to the finished object. The second method is especially ideal if you're making a garment that you plan to wear un-buttoned sometimes because the loops will be less prominent.
I hope that was clear, but let me know if you have any questions.