Guide to Mashing and Sparging
Mashing is a process used during all grain brewing to convert the starches in the grain to sugars. Depending mostly on the temperature and time of the mash a variety of sugar compositions can be produced. Brew in a bag (BIAB) is an easy way to go about mashing grain with very little special equipment. In fact, the only thing you’ll probably need to buy is a paint strainer bag. If the crushed grain mixture, or grist, is primarily malted barley there is generally enough amylase enzymes are naturally present to convert all of the starch to sugars in under an hour. A mash temperature of 150°F (65°C) for one hour will generally produce a 75% fermentable wort. Every degree Fahrenheit that the temperature is increase will lower the fermentability by 1%. By increasing the time that the mash is conducted for the fermentability can be increased. That’s it in a nut shell, but chapters in books have been written about just mash enzymes. The ratio of water to grain, or grist ratio, is typically about 1.5 quarts of water to 1 pound of grain. (Or 3 liters of water per kg of grain) Variations in grist ratio will not change fermentability much, but will affect efficiency. 
Efficiency is how much sugar is extracted out of the maximum possible sugar extraction. After being mashed the grains are drained into the boil kettle. This is known as laughtering. Some of the wort is absorbed by the grains which also retains some of the sugar. The more grain in the mash tun, the more water is absorbed. This accounts for a majority of the loss when evaluating overall efficiency. (Known as laughtering efficiency) Typically grain will absorb 0.2 gallons of water per pound of grain. (1.7 liters per kg) In addition each pound of grain will displace 0.1 gallons per pound of grain. To make a higher gravity beer, more grain is required, which means more water is absorbed and more volume is displaced in the mash tun. Depending on the size of your tun there is actually a point where adding more grain will lower the gravity of your wort instead of increasing it. For a single infusion mash, laughtering efficiency is the wort out divided by water in. The equation below shows how efficiency is impacted by increasing the amount of grain in the tun, but in a nut shell exceeding more than 2 pounds of grain per gallon of water will result a decrease in sugar content of the wort. Where E is the efficiency, V is the volume of water added to the mash tun in gallons, W is the weight of grain in pounds. In addition to time and temperature it is important to keep the pH near 5.1 for optimal enzyme activity while mashing. There are online calculators to help with this  or pH can be measured and adjusted with acid.
Factors that don’t affect fermentability as much are: grist ratio, crush, mineral content. In extreme circumstances the grain crush can affect fermentability. If the grain is crushed so poor that a significant portion of the grain is not broken then efficiency will suffer. Mineral content can affect efficiency if it impacts the pH. At the end of the saccharification mash rest (the conversion of starches to sugars) the temperature of the grain can be raised above 160°F to denature the enzymes to stop their activity. This will “lock in” the sugar profile that you have created. This can be accomplished by applying heat if you are using a direct fired mash tun, or by adding hot water to the mash tun if you are using a cooler-tun.