Among the methods available to reduce water production, injecting a gelling system composed of a polymer and a crosslinker has been widely used. In this work, a hydrogel was prepared by crosslinking of an aqueous solution containing hexamethylenetetramine (HMTA) as crosslinker, hydrochloric acid (HCl) as an activator, and the co-polymer of 2-acrylamido-2methyl-propanesulfonic-acid sodium salt (AMPS) and acrylamide (PAMPS). In order to indicate the effective factors on the gelation time and also to develop the quadratic mathematical models, central composite design (CCD) was applied. Therefore, the main purpose was to establish functional relationship between the three factors (polymer concentration, HMTA, and hydrochloric acid) and a response (gelation time) by using a statistical technique. In order to determine the optimum value of these factors for maximum gelation time, a simultaneous optimization was also applied. The results of the analysis of variance (ANOVA) of the developed model illustrated that the fitted model was significant in a 99% confidence limit. The results showed that hydrochloric acid was identified as the main factor effecting the gelation time and there was also an interaction between HMTA and hydrochloric acid. Finally, a mechanism for the reaction between PAMPS and HMTA were presented.