The buttonhole stitch is visually similar to the blanket stitch, but uses a different method of sewing.

Traditionally, this stitch is used to secure the edges of buttonholes as it gives a much sturdier stitch due to the knots it makes. But, over time, it came to be confused with the balnket stitch as these two stitches are used for the same purpose, that is, securing fabric edges.

A buttonhole stitch is best done with a slightly thicker thread.

I have illustrated this stitch between two horizontally parallel lines. This stitch can be done in any direction.

buttonhole_stitch_1      buttonhole_stitch_2
Fig 1: Bring the needle out through A. Now, loop the thread around from left to right. Take the needle in through B and bring it out from C, as shown. Keep the thread below the needle always.   Fig 2: Pull out the needle towards the top. This creates a small knot near the point B. 
DO NOT pull the needle downwards as it will not give the desired results. 
 buttonhole_stitch_3   Fig 3: A finished portion of the buttonhole stitch would look like this. A thicker thread would have revealed the knots better.