MG stands for middle grade, which means the book is intended for children 8 to 12 years old. Middle grade novels come between chapter books and young adult novels.
Here is an overview of each category, to see where the middle grade novel fits in:
Picture Books are intended for very young children, age 0 to 7. They are normally no longer than 32 pages and have 1,000 words at the very max. They are often read to the child by an adult.
Once children can read on their own (generally age 5 to 9), they can move on to Beginning Readers and Chapter Books. These books feel more like novels, but still have many pictures and a lot of space among the text. They are still relatively short compared to novels, maximum 3,500 words for beginning readers and 10,000 words for chapter books.
Then come the Middle Grade Novels, for confident readers aged 8 to 12 (13-14 for Upper Middle Grade). They average 20,000 to 45,000 words. The protagonist is typically the same age as the target audience, or slightly older. Kids read up. They will most likely be interested in reading about a character a little older than they are. This article by Kristi Holl talks about writing the middle grade novel and describes very well what this age group is about.
Once kids outgrow MG novels, they move on to Young Adult Novels (YA), intended for 12- to 18-year-old readers. These novels average 45,000 to 70,000 words. The main differences are the age of the protagonist (normally a teen) and the theme of the novel being more relevant to a teen audience.
Sometimes the difference between MG and YA can be blurry. The word count is debatable, as there are MG novels that are longer than average and YA novels that are shorter. The age of the protagonist is a good indicator, but there are always exceptions. Debbie Ohi's article on MG v/s YA explains more in detail how to tell the difference between the two.
To find out a book's word count and its interest level, use Renaissance Learning's website. On this site, Lower Grades stands for Picture Books, Beginning Readers and Chapter Books; Middle Grades is for Middle Grade (obviously), Middle Grades Plus stands for Upper Middle Grade, and Upper Grades is for Young Adult.
Please note: The word counts I used are based on several articles I've read, mainly from Chuck Sambuchino at Writers Digest and from Casey McCormick's blog. Every article I found about word count seems to show different numbers, so it's hard to figure out which one is correct. This is just to give a general idea.