This paper deals with the problem of obtaining numerical estimates of the accuracy of approximations to solutions of elliptic partial differential equations. It is shown that, by solving appropriate local residual type problems, one can obtain upper bounds on the error in the energy norm. Moreover, in the special case of adaptive h-p finite element analysis, the estimator will also give a realistic estimate of the error. A key feature of this is the development of a systematic approach to the determination of boundary conditions for the local problems. The work extends and combines several existing methods to the case of full h-p finite element approximation on possibly irregular meshes with elements of non-uniform degree. As a special case, the analysis proves a conjecture made by Bank and Weiser [Some A Posteriori Error Estimators for Elliptic Partial Differential Equations, Math. Comput. 44, 283-301 (1985)].