Well, it’s more nuanced than that.
Despite many hoaxes and dubious claims, dogs can’t actually count, at least not without extensive training — but dogs are aware of quantities and relative sizes, without any training at all. And, it turns out, they use the same part of their brains that humans do to assess the approximate number of items in an array or group of items.
About those treats — they definitely know when they are being shorted, or the other dog is getting a bigger piece. And they always know when there is (or recently was) a treat in your pocket. They have excellent noses, you know.
Researchers at Emory University (including my favorite dog researcher, Dr. Gregory Berns) put their well-trained dogs back into the MRI and showed them various groupings of black dots on gray backgrounds. This study doesn’t sound like it was as much fun for the dogs as the ones where they got ordinary treats and good treats so the researchers could see how the pleasure centers in their brains lit up … but I bet the dogs were paid well in treats after all the dots.
The published paper talks a lot about the different parts of the brain, but the upshot is that humans and dogs (and lots of other mammals, apparently) react differently when seeing a small quantity of something (fewer than 4) vs. a larger quantity. This useful skill, called numerosity, benefits both predator and prey animals in their search for food or attempts to avoid becoming food.
The dogs in the study had no math training prior to their MRI experience. The advanced mathematical skills that (some) humans possess use the same area of the brain. I wonder how far the above-average dog could get in math with the right teacher.