Whether it's James Damore at Google or an overconfident lab partner in biology class, women in science, technology, engineering and math (STEM) careers are told time and time again that they are not as smart as their male counterparts.

Now, a new study suggests that men aren't better at science, they just think they are - and that makes all the difference.

The study, which examined an undergraduate biology class, suggests that men overestimate their own intelligence, while underestimating the brainpower of their female colleagues.

At the same time, the study suggests women are plagued by feelings of academic self-doubt, even when their grades reveal they are just as smart.

"This echoes what has been previously shown in the literature; a review of nearly 20 published papers on self-estimated intelligence concluded that men rate themselves higher than women on self-estimated intelligence," the study concludes.

In the study's undergraduate biology class, the average grade was 3.3, which means that statistically half of the students should be above the average and half below it.

However, when students were asked where they sat in comparison to the class, the average male student thought he was smarter than 66 percent of the class, and the average female student thought she was smarter than 54 percent of the class.

The students were then asked to rate their academic abilities in comparison to their closest classmate. When comparing themselves to just one other person, men thought they were smarter 61 percent of the time, while women thought they were smarter only 33 percent of the time.

These differences were observed by the researchers even when they controlled for prior academic ability, which has been found to impact academic self-confidence.

It's not clear exactly why men tend to overestimate their scientific abilities, while women tend to judge their intelligence much more harshly, but there are a few theories.

"Really bright girls often don't feel like they know something unless they very much understand it, whereas boys are more comfortable saying they understand something without having an actual deeper understanding," Ilana Seidel Horn, a professor of mathematics at Vanderbilt University, told NBC.

The problem may also be rooted in the way science is taught in the classroom. For instance, studies have shown that greater self-confidence leads to greater participation, which in turn leads to greater learning and motivation.

In a self-fulfilling cycle, lower self-confidence may be holding women back from speaking up or taking leadership roles in science class.

"More and more of these studies are painting similar pictures," said co-author Sara Brownell.

"Females are not participating as much in science class. They are not raising their hands and answering questions."

In order to tackle this problem, the study suggests teachers "may need to structure participation so it happens more equitably, regardless of academic self-concept."

"Future studies may want to explore the extent to which academic self-concept is malleable and to what extent instructor behavior or course structure could influence it," the authors wrote.

No doubt, negative stereotypes of women in STEM also play a role in how men and women perceive their own intelligence.

Unsurprisingly, previous studies have shown that the greatest gender differences in estimated intelligence occur in physics, math and spatial tasks, which have been stereotypically touted as "male" specialties.

Brownell said she chose to focus on biology for this exact reason.

"Unlike the more male-dominated fields like engineering and physics, biology is seen as a safe place for women," Brownell explained.

By showing that gender biases exist even in "female-friendly" STEM disciplines, the study reveals just how ubiquitous and harmful gender biases can be for women pursuing STEM careers.

The study was published in Advances in Physiology Education.

Science AF is ScienceAlert's new editorial section where we explore society's most complex problems using science, sanity and humor.