Clustering of Mg in Al–Mg binary alloys is studied by means of atomistic simulations. The phenomenon is analysed in the undistorted Al lattice, as well as in the presence of dislocations. In the undistorted lattice, Mg has a tendency to cluster in a coherent phase. The binding energy of this structure is rather low and it dissolves at room temperature, and only dynamic associations of doublets or triples of solute atoms are observed. Increasing the temperature above 100°C inhibits the formation of any solute short range order. The application of a homogeneous hydrostatic strain has no effect on clustering. In the presence of dislocations and at room temperature, Mg clusters at cores forming the coherent phase observed in the undistorted lattice at low temperatures. Clustering at the cores of all types of dislocations is discussed. It is shown that the size, shape and structure of the cluster cannot be predicted using elementary calculations based on the pressure field generated by the unclustered dislocation. Furthermore, the field of the clustered dislocation is observed to differ from that of the unclustered defect, even at distances as large as 20 Burgers vectors from the core. The variation of the stacking fault due to clustering is determined by simply monitoring the distance between partials, which is observed to decrease upon clustering.