There are many things to keep in mind. First, don’t rely on your sense of direction to keep you straight. Very few people walk in a straight line and there is no such thing as intuitive sense of direction. (You can test this by blindfolding yourself and trying to walk in a straight line, or even just from one side of the field to the other.)
What you need to keep from getting lost are good, common sense and attention to detail. To begin with, know where you started from. Take the time to look at a map of the area and get familiar with the landmark so you will recognize them when you see them. Memorize the details as you hike.
Look for streams, unusual rocks, patches of flowers, anything that you will remember. A good trick is to tell a little story as you go incorporating the details you see. You will remember them better and will track them in order as you retell the story on your way back out.
Timing yourself works pretty much the same way. If you know how long you’ve been hiking you can predict how long it will take you to reach certain spots on the way back. Be sure to look back from time to time, as your path can look quite different from the other direction. If you’re really worried about getting lost, you can leave little trail markers in the form of a rock pile or broken stick every thirty paces or so.
Do not leave flagging tape; that encourages others to follow your path and create a false trail. If you leave any kind of markers, be sure to remove them and restore the area on the way out. Track the sun, it gives you a general east/west direction. In the winter the sun stays lower in the sky and tracks on a more southeasterly route. This is particularly so in northern latitudes. You can also use your watch and the sun to get a general sense of direction. If you point the 12 at the sun and draw a line halfway between the 12 and the hour hand it will point to north.
Alternately, pointing the hour hand towards the sun and drawing a line between it and the 12 will give you a line pointing south. You can also, to some extent, use the wind. Wind is very finicky and not reliable on a day to day basis. But you can be aware of overall wind patterns and where the wind usually comes from. In the United States, most of our weather comes from the prevailing westerlies and tracks west to east across the country.
Certain geographic formations, such as lakes or mountains, can also form prevailing wind patterns. You can see this in the trees, particularly in wind swept areas. They are called flag trees and tend to grow all their branches on one side, (The side facing away from the wind). If you see cut off stumps and can check the rings, the tree might actually have grown more, and have wider rings on the leeward side. You can even orient yourself with the North Star if you know how to find the Big Dipper. Naturally, knowing what direction north is doesn’t help much if you don’t know which direction you need to walk to get out.
Take note of what direction you are heading before you go in and every time you change direction. To keep yourself going fairly straight in that direction line up landmarks, even trees and be alert to where ridges, hills, gullies and streams are in relation to you. Count your paces every time you veer off your straight path to avoid an obstacle and then pace back onto your line.