Mammatus are hanging lobes on the underside of clouds. Although many different mechanisms have been proposed for their formation, none have been rigorously tested. In this study, three-dimensional numerical simulations of mammatus on a portion of a cumulonimbus cirruslike anvil are performed to explore some of the dynamic and microphysical factors that affect mammatus formation and evolution. Initial conditions for the simulations are derived from observed thermodynamic soundings. Five observed soundings are chosen-four were associated with visually observed mammatus and one was not. Initial microphysical conditions in the simulations are consistent with in situ observations of cumulonimbus anvil and mammatus. Mammatus form in the four model simulations initialized with the soundings for which mammatus were observed, whereas mammatus do not form in the model simulation initialized with the no-mammatus sounding. Characteristics of the modeled mammatus compare favorably to previously published mammatus observations. Three hypothesized formation mechanisms for mammatus are tested: cloud-base detrainment instability, fallout of hydrometeors from cloud base, and sublimation of ice hydrometeors below cloud base. For the parameters considered, cloud-base detrainment instability is a necessary, but not sufficient, condition for mammatus formation. Mammatus can form without fallout, but not without sublimation. All the observed soundings for which mammatus were observed feature a dry-adiabatic subcloud layer of varying depth with low relative humidity, which supports the importance of sublimation to mammatus formation.