We study surface nanobubbles using molecular dynamics simulation of ternary (gas, liquid, solid) systems of Lennard-Jones fluids. They form for sufficiently low gas solubility in the liquid, i.e., for large relative gas concentration. For strong enough gas-solid attraction, the surface nanobubble is sitting on a gas layer, which forms in between the liquid and the solid. This gas layer is the reason for the universality of the contact angle, which we calculate from the microscopic parameters. Under the present equilibrium conditions the nanobubbles dissolve within less of a microsecond, consistent with the view that the experimentally found nanobubbles are stabilized by a nonequilibrium mechanism.