Gas escape from volcanic conduits plays an important role in eruption dynamics and eruptive cycles. Gas volume fraction influences magma permeability, but permeability is also likely to depend on prior gas volume fraction through a hysteretic relationship. We study how this permeability behavior affects vertical segregation of gas and compaction of ascending magma. Ascent of vesiculated magma leads to compaction profiles in which gas volume fraction and permeability decrease substantially with height. Classical and hysteretic permeability functions can, however, lead to very different permeability profiles. If the magma ascent velocity is small enough, the hysteretic behavior introduces a step in the permeability profile such that a low-permeability plug sits on top of a gas-rich magma and acts as a trap for gases rising from depth. Time-dependent solutions take the form of porosity waves, although in the hysteretic case, gas is more concentrated into a thinner wave for a given amount of gas, leading to more powerful eruptions. This model shows that a highly vesicular magma can change into a degassed magma over a short distance, which has implications for phenomena such as seismicity, ground motion and eruptive behavior. (C) 2009 Elsevier B.V. All rights reserved.