If you’ve ever seen a cow staring vacantly across a field, or a pig rolling around in its own filth, you might not think there’s a lot going on in their head. You wouldn’t be alone. People haven’t given much credence to the intelligence of farm animals, and neither have scientists. But that’s starting to change.

A growing field of research is showing that—when it comes to the minds of goats, cows, and other livestock—we may have been missing something big. Studies published over the past few years have shown that pigs show signs of empathy, goats rival dogs in some tests of social intelligence, and cows can be potty trained.

Much of this work is being carried out at the Research Institute for Farm Animal Biology (FBN) in Dummerstorf, Germany, one of the world’s leading centers for investigating the minds of creatures that often end up on our dinner plate. From cows making friends to goats exhibiting signs of altruism, farm animals are upending popular—and scientific—conceptions of what’s going on in their minds.

The work may not just rewrite our thinking about livestock, it might also change how we treat them. As Jan Langbein, an applied ethologist at FBN told says, ‘If we don’t understand how these animals think, then we won’t understand what they need. And if we don’t understand what they need, we can’t design better environments for them.’