A fence looks neatest and is simplest to install if it runs in a straight line, with the posts exactly the same distance apart as the panels or rails. Spending some time carefully laying out the location of the posts before you dig the holes prevents mistakes later and gives you a fence that's pleasing to the eye, even if your land isn't level. Mow weeds and clear brush from the fence line before you start, so you can work in the area easily.
Pound stakes into the ground with a hammer, 2 to 3 feet beyond where you want a straight line of the fence to start and end. If the fence has several straight sections, such as a square fence around a yard, you'll need to measure each straight section separately.
Tie a string tightly between the stakes to mark a straight line. Use a level to check that the string is level if the land is approximately flat. On a slope, adjust the string so it follows the main contour of the slope, the way you want the fence to run.
Mark the ground under the string with spray paint where you want the first post to go. Mark the location of the last post also. Measure the distance between the two marks in feet, using a tape measure.
Divide the distance by the spacing that you want between each post. A typical spacing is 8 feet, though it might be 6 feet or some other length, depending on your fence panels or rails. If the result isn't a whole number, decide where you want the short panel to be and start measuring at the other end of the fence line.
Measure 8 feet or whatever your spacing is, starting at the first spray-paint mark and following the string. Spray-paint a mark there for the next post. Continue measuring and marking the distance, following the string.
When you install the posts, set them so they're all the same height as measured up from the string rather than the ground. The fence will be level even if the ground rises and falls slightly. If the land obviously changes from one slope to another in the middle of the fence line, add another stake where it changes and run the string in two sections, following the two different slopes of the land. If the land slopes steeply and the string is more than a few inches above the ground, measure along the string and hold a plumb bob at the correct distance on the string. Mark the ground directly underneath the plumb bob for the post hole.