The paper discusses some public key algorithms such as DH, RSA, DSA, ECDH and ECDSA and also gives mathematical explanations on the working of these algorithms. The paper also gives a brief introduction to modular arithmetic, which is the core arithmetic of almost all public key algorithms.