Previously proposed models of wettability change have not been tied to the chemistry that controls wettability but instead were driven by simplistic criteria such as salinity level or concentration of an adsorbed species. Such models do not adequately predict the impact of brine compositional change and therefore cannot be used to optimize brine composition. In this work, after testing proposed models in the literature on sandstones and carbonates, we propose a mechanistic surface-complexation-based model that quantitatively describes observations for ionically treated waterfloods. To the best of our knowledge this is the first surface-complexation-based model that fully describes ionic compositional dependence observed in ionically treated waterfloods in both sandstones and carbonates. We model wettability change by directly linking wettability to brine chemistry using detailed colloidal science. Brine has charged ions that interact with polar acidic/basic components at the oil-water interface and rock surface and therefore oil/brine and rock/brine interfaces are charged and exert both Van der Waals and electrostatic forces on each other. If the net result of the forces is repulsive, the thin water film between the two interfaces is stable (i.e., the rock is water-wet) otherwise, the thin water film is unstable and the rock becomes oil-wet. Based on Hirasaki (1991), we describe a ratio of electrostatic force to Van der Waals force with a dimensionless group, called “stability number,” where rock wettability is water-wet for values greater than one and oil-wet for values less than one. For sandstones, the zeta potentials of oil/brine and rock/brine interfaces become more negative/less positive by diluting or softening the brine and/or increasing pH. Similarly, for carbonates, dilution and/or sulfate enrichment of brine makes surface potentials more negative. Such brine modification can therefore be used to improve oil recovery. We implemented the improved wettability change model in a comprehensive coupled reservoir simulator, UTCOMP-IPhreeqc, in which oil/brine and rock/brine zeta potentials are modeled using the IPhreeqc surface complexation module. We take into the account total acid number (TAN) and total base number (TBN) for the oil/brine interface and we use rock surface reactions for brine/rock surface potential modeling. Surface potentials obtained from the geochemical model are used to calculate the dimensionless group controlling wettability change, which is dynamically modeled in the transport simulator. The model is validated in sandstones and carbonates by simulating an inter-well test, and several corefloods and imbibition tests reported in the literature. For sandstones, we model Kozaki (2012) and BP's Endicott trial. For simple dilution in carbonates we model experiments by Shehata et al. (2014) and Yousef et al. (2010). For enrichment with sulfate we model Zhang and Austad (2006) and for increasing total ionic strength via sodium chloride enrichment, Fathi et al. (2010a).