Always buy your windows before you build the rough window opening in your wall. If you try to build a window opening and then buy a window to fit, you may find it difficult to find a window the exact right size. This typically means that you must rebuild the opening or incur the increased cost of buying a custom window. Instead, buy your windows and then follow the manufacturer's instructions, which should exactly state how big the rough opening needs to be.
If you have to cut into an existing wall to make space for a new window, you need to consider a few things other than the window itself when you cut the rough opening. First, calculate the size of the window you want. Then, add two extra inches to the height and width of those measurements. Finally, add another 3 inches to the total width measurement, because you need to install studs at the sides of the window.
Always make sure that if you are going to err on one side of your measurements that you fall on the side of making the opening slightly too large. If you cut an opening that is too wide or too tall, you can use some thin shims to shore up the opening to the correct size. Leave a 1/2 inch of extra space on each side of the window to provide a safe margin of error. An opening that is cut too small is more difficult to deal with, especially if you don't realize the problem until after the header and sill are installed.
A rough opening doesn't always turn out perfectly square and plumb. Verify how close it is by measuring at three points across each of the height and the width. Measure from the corners and in the middle. If the height or width changes more than an inch across the entire opening, you need to cut some tapered wedges out of discarded studs to level out the opening before moving on to window installation.