In water, under standard conditions, we know that the following equilibrium occurs:
#2H_2O rightleftharpoons H_3O^+ + HO^-#
As for any equilibrium, we can measure the equilibrium constant, #K_w#, of this reaction:
#K_w=[H_3O^+][HO^-]=10^-14#.
Given that #K_w=10^-14#, and taking #-log_10# of both sides, we get the defining relationship:
#-log_10K_w# #=# #-log_10[H_3O^+]-log_10[HO^-]# #=# #-log_(10)10^-14#.
Thus #14=pH+pOH#, and this is something that you have to commit to memory.
And thus when quoted #pK_a# for weak acids etc. you have to solve the equilibrium expresssion:
#HA+ H_2O rightleftharpoons H_3O^+ +A^-#.
There should be many model answers on these boards. Here is a start, and here is another attempt.