Ideally when you are hiking you have enough water. The next best situation would be having a quality filter and purification system. In the absence of all of that you can make a survival filter from debris you can often find on the trail. This while not an ideal option can be a great emergency option that is preferable to not having anything at all.
The first caveat is before starting this filter look around and make sure there is not chance that you will not need drinking water. This filter is by not means ideal or guaranteed to make the water safe to drink. It is better than nothing.
Watch of for turbid or hazy water. This water can be more difficult to make drinkable. If you have multiple options try to get clearer water. Sometimes this may be as easy as digging a seepage well while lets the water percolate up and often reduces the turbidity of the water.
Just like cooking you need to first gather ingredients to make your survival filter. The key ingredients are a bottle (preferably plastic), dry grass, sand, and rocks or charcoal (ideally charcoal).
Cut off the bottom of a bottle and punch a hole on two opposite sides of the bottle approximately one inch from the bottom of the bottle.
Make sure the cap of the bottle is screwed in very tightly. Then take about 3 tablespoons of dry grass and place them in the bottle neck packing it very tightly. This is the plug to keep everything else from falling out of the mouth of the bottle.
Next put a layer of ideally charcoal. You can create this by partially burning wood if you can not find charcoal in a firepit. It is great for absorbing things. If you absolutely can not get charcoal and cannot create a fire to generate it then use small sandstone rocks. Although please note rocks have very minimal absorbing properties and are vastly inferior to charcoal.
Now take some sand and add it on top of the charcoal. This will help filter the water even better. Do not work if some fills the gaps between the pieces of charcoal.
Now take more of the dried grass and put a layer on top of the sand. This will help form a filter to remove some of the floating debris. You can cover this layer with a piece of cloth if you have some for extra filtration. However this is not necessary.
Hang or Hold
Now you have the option to either hand this up as you filter or hold it. You can string a cord or piece of cloth through the hole in the top so the mouth of the bottle is facing down. This makes it easier to filter because you have both hands free. However, you can skip this step and hold the bottle or have someone hold it for you.
Now you just pour water into the top and let it filter down the layers. Then open the cap at the bottle and collect the water in a container. Last note, this is an emergency last option, not an ideal way to clean water.