Pour clear silver nitrate solution into clear sodium chloride solution and a white cloud forms at once. Both solutions were full of free ions: Ag+ and NO3− in one, Na+ and Cl− in the other. When they mix, Ag+ meets Cl−, and silver chloride does not dissolve, so it drops out as a solid: AgNO3+NaCl→AgCl↓+NaNO3. The cations have traded anions, AB+CD→AD+CB.
Writing the products takes two moves. First swap the partners, pairing each cation with the other compound's anion. Then rebuild each formula from the charges instead of copying the old subscripts. In BaCl2+Na2SO4 the new pairs are Ba2+ with SO42−, giving BaSO4, and Na+ with Cl−, giving NaCl. Balanced: BaCl2+Na2SO4→BaSO4↓+2NaCl.
Mixing is not the same as reacting. Pour sodium chloride solution into potassium nitrate solution and nothing happens: the would-be products, NaNO3 and KCl, both dissolve, so all four ions keep drifting around as before. A double displacement needs a driving force that pulls ions out of solution: a precipitate such as AgCl, a gas such as the CO2 from a carbonate and an acid, or water from an acid and a base.
Think of it like this. Double displacement is like two dance couples swapping partners: each positive ion leaves with the other couple's negative ion. The swap only sticks if one new pair refuses to separate, by forming a solid, a gas or water; otherwise everyone keeps drifting around the floor and nothing has really changed.
Core idea. Two ionic compounds swap partners, AB+CD→AD+CB, but only when the swap removes ions from solution by forming a precipitate, a gas or water; otherwise the ions simply stay mixed.