Magnetohydrodynamic (MHD) stability limits for the n = 1 internal kink mode in a tokamak are investigated. As the intemal kink mode is a weak instability, accurate equilibrium solutions are required to determine its stability boundaries. For this purpose, a numerical equilibrium code called CHEASE using Hermite bicubic elements has been developed. The code computes equilibria and provides a mapping to flux coordinates for MHD stability calculations. Several test cases are studied to show the convergence rate of the equilibrium. Convergence tests are also presented for the eigenvalues of the stability calculations when the equilibrium mesh is varied. Using CHEASE and the toroidal resistive MHD stability code MARS, effects of current profile, plasma cross-section and resistivity on the stability of the internal kink mode are investigated for tokamak equilibria. The results show that the internal kink mode is more unstable than previously thought. The numerical ideal stability results for a circular plasma cross section are compared with the results obtained by an analytic large aspect ratio expansion. It is found that the internal kink is significantly destabilized by the ellipticity of the plasma cross section combined with low shear. A large aspect ratio expansion of the Mercier and the resistive interchange criteria retaining effects of ellipticity and triangularity is given, showing analytically the destabilization by ellipticity. For resistive internal kink modes, the stabilizing effect of small aspect ratio is confirmed, but as for the ideal case, the stability is very sensitive with respect to shaping of the plasma cross section. For finite pressure and small resistivity, only a very restricted set of equilibria is stable to the internal kink mode.