pH calculation can be - depending on the system - very easy, or extremally complicated. There are three reasons. First of all, most acids and bases are weak and to calculate concentration of H+ one have to find out exact equilibrium of the system - the more compounds present, the more interactions have to be taken into account and the more difficult calculations are. Second, water by itself is a source of H+ cations due to autodissociation, which plays important role in diluted solutions of acids and bases (that's why pure water has pH=7). Third, in case of solutions more concentrated than 0.01M (or even 0.001M) activities start to play important role, which makes calculations even harder.
In case of diluted - but not very diluted - strong acid, like HCl, we can assume that activity of H+ equals its concentration and that acid is completely dissociated. Thus pH of 10-4M HCl solution is just
However, if the solution is very diluted - say 10-7M - this easy approach is not sufficient, as the pH of such solution is not 7 - but 6.79, due to H+ from water autodissociation.
In case of weak acid (acetic acid for example) apart from water autodissociation you have to take equilibrium constant for the dissociation into account. In general it leads to cubic equation, which in most cases can be simplified to quadratic, as usually concentration of acid is high enough to allow neglection of water autodissociation. Explanation of the process is out of scope of this site, please refer to the pH calculation lectures where this problem is addressed in details.
If you have to calculate pH of solution, but you are not interested in detailed explanation and theory of such calculations, we strongly advice you to use BATE - pH calculator program. If you are looking for a way of calculating composition of buffer, use Buffer Maker - buffer calculator.