When lost in the woods, the only way to make progress is by means of informed decisions. Having the ability to make an improvised compass could make the difference between finding your way out of the woods or wandering aimlessly. It’s very possible to end up lost without any of the necessary supplies to make a compass. However it’s better to have the knowledge without the resources than to have the resources and not know what to do with them.
Rub a needle or similar piece of iron-containing metal against a magnet. The needle should become magnetically charged. All speakers have magnets, so you may be able to find a magnet in a radio, cell phone or a pair of headsets. An alternative way of giving a needle a magnetic charge is with a battery and wire. If the wire has no insulation, wrap the needle with a leaf to keep it from contacting the wire. Wrap the wire around the needle as many times as you can, and run a current through the wire with a battery. It's a common myth that rubbing a needle against fur or fabric is another method, but doing so only gives it a static charge. It doesn't magnetize the needle nor do any good for making a compass.
Place a small leaf in a pool of water so it floats. Make sure there is no current or wind that could disturb it.
Set the needle on the leaf. Depending on how well it's magnetized, it could take as much as two minutes before the needle indicates a direction. After it does, the tip of the needle may be pointing either north or south. The position of the sun may make it obvious which is which, but during midday, you may need to look for other clues to determine which direction is north. When there is no water available, an alternative is to suspend the needle from a string. Keep the string shielded from the wind, and take into account the fact that the string's resistance to twisting can influence the direction.
Use landmarks around you to stay oriented. After deciding on a direction to follow, keeping on course can still be challenging, especially when trees are obstructing your view of any distant points of reference. In that case, use the trees themselves to guide you. Choose two distant trees that are in line with your direction such that one of them is about twice as far away as the other. When you reach the first, sight in the direction of the second to choose another tree. Continue in that way, using two trees to sight in the next in a leap-frog manner.