Middle grade is from 20,000 – 45,000, depending on the subject matter and age range. When writing a longer book that is aimed at 12-year-olds (and could maybe be considered “tween”), using the term “upper middle grade” is advisable. With upper middle grade, you can aim for 32,000 – 40,000 words. These are books that resemble young adult in matter and storytelling, but still tend to stick to MG themes and avoid hot-button, YA-acceptable themes such as sex, drugs and rock & roll. You can stray a little over here but not much.
With a simpler middle grade idea (Football Hero, or Jenny Jones and the Cupcake Mystery), aim lower. Shoot for 20,000 – 30,000 words.