I am not sure that anyone outside Paradox has the exact formula. .
In my latest game I sent a level1 general to china with 4 divisions he fought for about 5 months without gaining any experience. Is the most senior general in the battle getting all the experience gain? I seem to get better results on the offensive than on the defensive.