Countertop microwaves: Measure the height, width and depth of your current microwave or the space on your countertop or shelves you want it to occupy. You should account for 1" of ventilation space between the microwave and the wall behind it and at least 3" of space from the edge of the counter to the open microwave door to avoid tipping, Also,try to put at least two feet between the microwave and the range to help prevent a fire hazard.
Built-in microwaves: Measuring the height, width and depth of your existing microwave enclosure is more important than the measurements of your current appliance when it comes to over-the-range and built-in microwaves. Measure cabinet-to-cabinet, keeping in mind that it’s okay for over-the-range microwaves to drop below cabinets, as long as you retain 30" from the bottom of the microwave to the top of the stove. If you're installing the microwave oven near a left sidewall, make sure there is at least 6" of clearance between the wall and the microwave oven so that the door can open fully.
In addition to getting precise dimensions of your cutout, make sure there is space for ventilation per your manufacturer’s instructions. It’s important to note that built-in microwaves require professional installation.