Basic Allowance for Housing (BAH) is a US-based allowance provided to those in service based on their duty location, pay grade, and dependency status. The purpose is to provide compensation in order to allow those in service to seek appropriate, comfortable housing in the civilian market. The three primary factors in determining the rate of the payment (duty location, pay grade, and dependency status) each carry a particular logic and line of thought behind them.
Duty location matters because, as one expects, the cost of living varies drastically based on the area you live in. Housing in highly developed cities and areas with large populations such as New York City, Washington DC, or San Diego simply cost significantly more based on the sizable population and concentration of people. On the other hand, smaller cities built around military bases tend to have lower costs of living associated with them. Pay grade altering the rate of BAH compensation seems a given, but the simple explanation is that the level of comfort allowed to a service-member based on their BAH is adjusted based on their rank and time in service.
Dependency status is factored in because, as one would expect, costs increase when additional space is needed for more people. Thus, all three are factored in together in determining the appropriate BAH rate. Care to look up your current or past BAH rate? If you have a year in mind, your duty zip code from the time, and your pay grade at the time ? you can find data online quite easily (http://www.defensetravel.dod.mil/site/bahCalc.cfm).
A Monthly Housing Allowance (MHA) is a payment made by the VA that is received as part of an educational program. Generally, a MHA is the same as a BAH payment made for an E-5 with dependents. Instead of using your duty location to decide the MHA rate though, it is based on the zip code of the school itself. In essence, the MHA payment system was mostly built by drawing data off the existing BAH system and adapting it to the use of an educational program.