Density and flame retardancy controlled isocyanate-based polyimide foam was prepared by a postgrafting method. The first solution containing prepolymer that was synthesized by dianhydride and overdose isocyanates was added into the second solution containing dianhydride derivatives, water, catalysts, and surfactants. The possible reactions during preparation are discussed. The obtained Fourier transform infrared spectra indicate that an increased amount of imide rings was generated with increasing molar ratio of the anhydride/isocyanate groups. The size and walls of the cells became smaller and thinner with less carbon dioxide (CO2) escaping into the air during the first solution preparation process, as shown in scanning electron microscopy images. The thermogravimetric analysis curves demonstrated that the 5% weight loss temperature (T-5%) was greater than 289 degrees C, and the residual weight retention at 800 degrees C was more than 45%. In addition, differential thermogravimetry curves demonstrated that the thermal stability decreased with more byproducts in polyimide foams. The limiting oxygen index increased gradually from 30.63%+/- 0.56 to 48%+/- 0.50 with increasing molar ratio of the anhydride/isocyanate groups. Meanwhile, the density of obtained polyimide foams ranged from 38.31 kg/m(3)+/- 0.90 to 99.53 kg/m(3)+/- 10.85. When the molar ratio of anhydride/isocyanate groups ranged from 0.4 to 0.8, the prepared isocyanate-based polyimide foams all exhibit both great flame retardancy and lower density. (C) 2016 Wiley Periodicals, Inc.