We present an algorithm to photometrically calibrate wide field optical imaging surveys, that simultaneously solves for the calibration parameters and relative stellar fluxes using overlapping observations. The algorithm decouples the problem of "relative" calibrations from that of "absolute" calibrations; the absolute calibration is reduced to determining a few numbers for the entire survey. We pay special attention to the spatial structure of the calibration errors, allowing one to isolate particular error modes in downstream analyses. Applying this to the SloanDigital Sky Survey imaging data, we achieve ~;1 percent relative calibration errors across 8500 sq.deg/ in griz; the errors are ~;2 percent for the u band. These errors are dominated by unmodelled atmospheric variations at Apache Point Observatory. These calibrations, dubbed ubercalibration, are now public with SDSS Data Release 6, and will be a part of subsequent SDSS data releases.