The basic principles of automatic differentiation are described, namely the forward and reverse mode for the evaluation of the first and second derivatives. The implementation is discussed together with extensions and generalization of algorithmic differentiation techniques useful for nonsmooth optimization.