This can certainly be done by hand, but today we'll cover how you can do it with a sewing machine. First, you'll need a button. It goes right here in the buttonhole foot. You can adjust it to size.
Next, you'll want to attach the buttonhole foot to your sewing machine and pull the thread underneath. Turn the hand wheel and pull the thread through. Pull down the lever. Don't forget this step, or it won't work.
Place your fabric underneath. Bring the presser foot down. Follow your sewing machine manual for buttonhole settings. Mine says I need a width of 4~6.5, set the length setting to buttonhole, set the pattern to BH, thread tension of 1~5, and use the R foot.
Press on the foot pedal and there it goes. For this one, I reset the buttonhole settings and ran it a second time so it could have a more filled-in look. Now you can remove it and this is what it looks like.
You can also sew on a button by machine using the button sewing foot. I set the machine to a zigzag stitch and a length of 0. For the width, it depends on the button you are using. Check that the needle is in the right place before you start and adjust the stitch width as needed. Mine didn't quite line up, so to remedy that, I placed another button behind it. If you prefer a shank, you can place a pin between the button and the foot. Once it's all in place, press on the foot pedal. Repeat if necessary.
Trim the threads. Use a seam ripper or a buttonhole cutter to open the hole.
An expanding sewing gauge is a handy tool for spacing buttonholes, buttons, pleats, and much more. Watch this video to learn more.