From Generation 3 (Ruby/Sapphire) onward, Pokémon offspring will also inherit some of the Individual Values from the parents. (IVs are hidden values that improve your final stats.)
>The baby will inherit three stats from either parent. So if you were breeding a male Infernape and female Ninetales, the resulting Vulpix could inherit the HP and Defense IVs from Infernape and the Speed IV from Ninetales.
The IVs chosen are random and in the case of the same one being selected twice, the former would be overwritten with the latter. For example, if the game chose Ninetales' HP and Attack, then Infernape's Attack, then the baby would only inherit two IVs - the HP from Ninetales and Attack from Infernape.
From HeartGold/SoulSilver onward a new mechanic was added to control this. If either parent is holding one of the EV-training Power items then the child will inherit the corresponding IV. Two different IVs are randomly inherited from the parents as normal, and the remaining three are completely random. If both parents hold a Power item then one of the two stats is chosen at random. The power items are:
Power Weight icon Power Weight (HP)
Power Bracer icon Power Bracer (Attack)
Power Belt icon Power Belt (Defense)
Power Lens icon Power Lens (Sp. Attack)
Power Band icon Power Band (Sp. Defense)
Power Anklet icon Power Anklet (Speed)
So for example, holding the Power Belt means the baby will inherit the Pokémon's Defense IV and two random non-Defense IVs from either parent.
From X/Y onward, a parent holding the Destiny Knot item causes the baby to inherit five IVs from that parent. If the other parent holds a Power item, the baby will inherit the corresponding IV and then four random IVs from the Destiny Knot parent.
So basically, unless they're holding a Destiny Knot, the baby can only inherit 3 IVs, and the rest is random. I'd advise doing what it says at the bottom of this, and having the Ditto hold a Destiny Knot, this will increase your chances phenominally, as the baby will now always have 5 IVs, only missing SP Defense, then you just keep breeding until the baby gets the SP Defense IV naturally.
Source: The Breeding Page