Many crystals naturally grow in faceted shapes. For instance, common table salt forms cubes and quartz forms hexagonal prisms. These characteristic shapes are a consequence of the crystal structure of the material and the surface energy, as well as the general conditions under which the crystal formed.
The Bravais lattice of the crystal structure defines a set of possible "low-energy planes", which are usually planes on which the atoms are close-packed. For instance, a cubic crystal may have low-energy planes on the faces of the cube or on the diagonals. The planes are low-energy in the sense that if the crystal is cleaved along these planes, there will be relatively few broken bonds and a relatively small increase in energy over the unbroken crystal. Equivalently, these planes have a low surface energy. The planes with the lowest energy will form the largest facets, in order to minimize the overall thermodynamic free energy of the crystal. If the surface energy as a function of the planes is known, the equilibrium shape of the crystal may be found via the Wulff construction.
Growth conditions, including the surface the crystal is growing on top of (the substrate), may change the expected shape of the crystal; for instance, if the base of the crystal is under stress from the substrate, this may favor the crystal growing taller rather than growing outwards along the substrate. The surface energy, including the relative energies of the different planes, depend on many factors including the temperature, the composition of the surroundings (e.g. humidity), and the pressure.