Consider a weak acid in water:
#HA +H_2Orightleftharpoons H_3O^+ + A^-#
Now the equilbrium constant, #K_a#, describes this equilibrium:
#K_a = ([H_3O^+][A^-])/[[HA]]#
Now, as long as we do it to both sides, we can manipulate this equation. We take logarithms to the base 10 to make it a bit easier:
#log_10K_a = log_10{[H_3O^+]} + log_10{[[A^-]]/[[HA]]}#
(Note, when we write #log_ab = c#, we ask to what power do we raise the base #a# to get #b#; so #a^c=b#; likewise #log_(10)100 = 2,# and #log_(10)1000 = 3#. Before the days of ready access to electronic calculators, everyone would use log tables to perform multiplication and division.)
Rearranging this equation:
#-log_10{[H_3O^+]} = -log_10K_a + log_10{[[A^-]]/[[HA]]}#
But by definition #-log_10([H_3O^+])=pH#, and #-log_10K_a = pK_a#.
So finally, we get:
#pH = pK_a + log_10{[[A^-]]/[[HA]]}#.
Note that this tells us that at the point of half equivalence of a titration, when #[A^-]=[HA]#, #log_10(1)=0# (clearly), and thus #pH = pK_a# at half equivalence.