For free atoms, electron configurations have been determined by atomic spectroscopy. Lists of atomic energy levels and their electron configurations have been published by the National Institute of Standards and Technology (NIST) for both neutral and ionized atoms.
For neutral atoms of all elements, the ground-state electron configurations are listed in general chemistry and inorganic chemistry textbooks. The ground-state configurations are often explained using two principles: the Aufbau principle that subshells are filled in order of increasing energy, and the Madelung rule that this order corresponds to the order of increasing values of (n + ) where n is the principal quantum number and  is the azimuthal quantum number. This rule predicts for example that the 4s orbital (n = 4,  = 0, n +  = 4) is filled before the 3d orbital (n = 3,  = 2, n +  = 5), as in titanium with configuration [Ar]4s3d.
There are a few exceptions with only one electron (or zero for palladium) in the ns orbital in favor of completing a half or a whole d shell. The usual explanation in chemistry textbooks is that half-filled or completely filled subshells are particularly stable arrangements of electrons. An example is chromium whose electron configuration is [Ar]4s3d with a d electron count of 5 for a half-filled d subshell, although Madelung's rule predicts [Ar]4s3d. Similarly copper is [Ar]4s3d with a full d subshell, and not [Ar]4s3d. The configuration of palladium is [Kr]4d with zero 5s electrons. However this trend is not consistent: tungsten, a group VI element like Cr and Mo has a Madelung-following [Xe]6s4f5d, and niobium has a [Kr]5s4d as opposed to the Madelung rule predicted [Kr]5s4d which creates two partially-filled subshells.
When a transition metal atom loses one or more electrons to form a positive ion, overall electron repulsion is reduced and the n d orbital energy is lowered more than the (n+1) s orbital energy. The ion is formed by removal of the outer s electrons and tends to have a d configuration, even though the s subshell is added to neutral atoms before the d subshell. For example, the Ti ion has the ground-state configuration [Ar]3d  with a d electron count of 2, even though the total number of electrons is the same as the neutral calcium atom which is [Ar]4s.
In coordination complexes between an electropositive transition metal atom and an electronegative ligand, the transition metal is approximately in an ionic state as assumed in crystal field theory, so that the electron configuration and d electron count are those of the transition metal ion rather than the neutral atom.