We prove necessary and sufficient integral conditions involving extremal distance for a conformal mapping of the unit disk to belong to the Hardy or weighted Bergman spaces. We also give characterizations for the Hardy number and the Bergman number of a simply connected domain in terms of extremal distance.