We study cosmic variance in deep high-redshift surveys and its influence on the determination of the luminosity function for high-redshift galaxies. For several survey geometries relevant for Hubble Space Telescope (HST) and James Webb Space Telescope (JWST) instruments, we characterize the distribution of the galaxy number counts. This is obtained by means of analytic estimates via the two-point correlation function in extended Press-Schechter theory, as well as by using synthetic catalogs extracted from N-body cosmological simulations of structure formation. We adopt a simple luminosity-dark halo mass relation to investigate the effects of environment on the fitting of the luminosity function. We show that in addition to variations of the normalization of the luminosity function, a steepening of its slope is also expected in underdense fields, similar to what is observed within voids in the local universe. Therefore, to avoid introducing artificial biases, caution must be taken when attempting to correct for field underdensity, such as in the case of the HST UDF i-dropout sample, which exhibits a deficit of bright counts with respect to the average counts in GOODS. A public version of the cosmic variance calculator based on the two-point correlation function integration is available on the Web at STScI.