The present investigation concerns with the development and optimization of an in situ forming formulation using 3(3) full factorial design experimentation. Metformin, an antidiabetic drug with upper part of gastrointestinal tract as absorption window was used as a model drug. The formulations were designed with an objective to retain in stomach for an extended time period. The effect of three independent factors--concentrations of sodium alginate (X(1)), gellan gum (X(2)), and metformin (X(3)) on in vitro drug release were used to characterize and optimize the formulation. Five dependent variables-release exponent (Y(1)), dissolution efficiency (Y(2)), drug release at 30 min (Y(3)), 210 min (Y(4)), and 480 min (Y(5)) were considered as optimization factors. The data were statistically analyzed using ANOVA, and a p < 0.05 was considered statistically significant. Three dimensional surface response plots were drawn to evaluate the interaction of independent variables on the chosen dependent variables. Of the prepared 27 formulations, the responses exhibited by batch F17 containing medium level sodium alginate (X(1)), low level gellan (X(2)), and medium level metformin (X(3)) were similar to the predicted responses.