An easy and convenient method for the synthesis of cobalt and magnesium ferrite nanoparticles is demonstrated using liquid foams as templates. The foam is formed from an aqueous mixture of an anionic surfactant and the desired metal ions, where the metal ions are electrostatically entrapped by the surfactant at the thin borders between the foam bubbles and their junctions. The hydrolysis is carried out using alkali resulting in the formation of desired nanoparticles, with the foam playing the role of a template. However, in the formation of ferrites with the formula MFe(2)O(4), where the metal ion and iron possess oxidation states of +2 and +3, respectively, forming a foam from a 1:2 mixture of the desired ionic solutions would lead to a foam composition at variance with the original solution mixture because of greater electrostatic binding of ions possessing a greater charge with the surfactant. In our procedure, we circumvent this problem by preparing the foam from a 1:2 mixture of M(2+) and Fe(2+) ions and then utilizing the in situ conversion of Fe(2+) to Fe(3+) under basic conditions inside the foam matrix to get the desired composition of the metal ions with the required oxidation states. The fact that we could prepare both CoFe(2)O(4) and MgFe(2)O(4) particles shows the vast scope of this method for making even multicomponent oxides. The magnetic nanoparticles thus obtained exhibit a good crystalline nature and are characterized by superparamagnetic properties. The magnetic features observed for CoFe(2)O(4) and MgFe(2)O(4) nanoparticles are well in accordance with the expected behaviors, with CoFe(2)O(4) particles showing higher blocking temperatures and larger coercivities. These features can easily be explained by the contribution of Co(2+) sites to the magnetocrystalline anisotropy and the absence of the same from the Mg(2+) ions.