We present a routine that calculates the sky level of images. This routine is general in the sense that it can be applied to any image, independent of the instrument with which it was obtained, to get a reliable value for the sky background. This is achieved by optimizing the parameters of the calculation to give the best result for every frame. We compare the routine to other sky-calculating routines, and obtain similar or more reliable results with our routine in all cases. The routine is currently implemented as a FORTRAN program within VISTA image-processing software, and it may be provided as a stand-alone FORTRAN program after some minor changes.