Biomaterial aerogel fabrication by freeze-drying must be further improved to reduce the costs of lengthy freeze-drying cycles and to avoid the formation of spongy cryogels and collapse of the aerogel structures. Residual water content is a critical quality attribute of the freeze-dried product, which can be monitored in-line with near-infrared (NIR) spectroscopy. Predictive models of NIR have not been previously applied for biomaterials and the models were mostly focused on the prediction of only one formulation at a time. We recorded NIR spectra of different nanofibrillated cellulose (NFC) hydrogel formulations during the secondary drying and set up a partial least square regression model to predict their residual water contents. The model can be generalized to measure residual water of formulations with different NFC concentrations and the excipients, and the NFC fiber concentrations and excipients can be separated with the principal component analysis. Our results provide valuable information about the freeze-drying of biomaterials and aerogel fabrication, and how NIR spectroscopy can be utilized in the optimization of residual water content.