A lot of machines these days come with a buttonhole attachment. The problem is, I’ve never been able to figure out how the hell you use the blasted thing. So I do it the “old fashioned” way, according to the directions provided by the manual for my 60’s Kenmore.
I’ve found that something more like this works better for me. Remember to do a very tight zig-zag, like the guide above says, the stitch length should be almost to zero so the stitches lay right next to one another like a satin stitch in embroidery.
If you use a small piece of light fusible interfacing on the inside of the fabric, your button hole with look nicer and last longer.