Quantum correlations are larger than classical correlations but do not saturate nonsignaling correlations. Classical theories assign noncontextual outcomes, nonsignaling theories assign noncontextual probabilities for compatible measurements. We show that, for any set of experiments on identically prepared systems, there is a graph such that the classical, quantum, and nonsignaling bounds for the correlations are given by the independence number, the Lovász theta-function, and the fractional packing number of the graph (which were introduced for totally unrelated purposes, and can be computed with well-known techniques), respectively. This provides an efficient method to compute these bounds: the latter two are shown to have semidefinite and linear characterizations, respectively. We apply it to calculate the bounds (some of them previously unknown) for a wide range of Bell inequalities and Kochen-Specker proofs. Conversely, any graph corresponds to a set of experiments for which these bounds can be efficiently computed. This provides a tool to single out experiments with a large classical-quantum gap and candidates for loophole-free Bell tests, and a unified framework to discuss alternatives to and theories beyond