Context : The formation of high mass stars and clusters occurs in giant molecular clouds . Objects in evolved stages of massive star formation such as protostars , hot molecular cores , and ultracompact HII regions have been studied in more detail than earlier , colder objects . Further progress thus requires the analysis of the time before massive protostellar objects can be probed by their infrared emission . With this in mind , the APEX Telescope Large Area Survey of the whole inner Galactic plane at 870 \mu m ( ATLASGAL ) has been carried out to provide a global view of cold dust and star formation at submillimetre wavelengths . Aims : We derive kinematic distances to a large sample of massive cold dust clumps from their measured line velocities . We estimate masses and sizes of ATLASGAL sources , for which the kinematic distance ambiguity is resolved . Methods : The ATLASGAL sample is divided into groups of sources , which are located close together , mostly within a radius of 2 pc , and have velocities in a similar range with a median velocity dispersion of \sim 1 km s ^ { -1 } . We use NH _ { 3 } , N _ { 2 } H ^ { + } , and CS velocities to calculate near and far kinematic distances to those groups . Results : We obtain 296 groups of ATLASGAL sources in the first quadrant and 393 groups in the fourth quadrant , which are coherent in space and velocity . We analyse HI self-absorption and HI absorption to resolve the kinematic distance ambiguity to 689 complexes of submm clumps . They are associated with ^ { 12 } CO emission probing large-scale structure and ^ { 13 } CO ( 1-0 ) line as well as the 870 \mu m dust continuum on a smaller scale . We obtain a scale height of \sim 28 \pm 2 pc and displacement below the Galactic midplane of \sim - 7 \pm 1 pc . Within distances from 2 to 18 kpc ATLASGAL clumps have a broad range of gas masses with a median of 1050 M _ { \odot } as well as a wide distribution of radii Their distribution in galactocentric radii is correlated with spiral arms . Conclusions : Using a statistically significant ATLASGAL sample we derive a power-law exponent of -2.2 \pm 0.1 of the clump mass function . This is consistent with the slope derived for clusters and with that of the stellar initial mass function . Examining the power-law index for different galactocentric distances and various source samples shows that it is independent of environment and evolutionary phase . Fitting the mass-size relationship by a power law gives a slope of 1.76 \pm 0.01 for cold sources such as IRDCs and warm clumps associated with HII regions .