Models and estimates of Earth’s human carrying capacity vary widely and assume, rather than solve for, binding environmental constraints (the process or resource in shortest supply relative to human biological needs). The binding constraint, and therefore the true upper bound on the number of humans that Earth could sustain indefinitely, remains unknown."
Source : Humanity’s Fundamental Environmental Limits , Human Ecology, volume 48, pages235–244
In 2020, a research team from St Olaf College and the University of Oregon, US, modeled two populations of interest, primary producers (plants) and humans, in a global, managed ecosystem, with 'ideal' technological support.
The finding was that :
With ideal technology, human carrying capacity runs into the tens of trillions, while with currently demonstrated technology Earth could support more than 200 billion humans. These numbers reflect neither a desirable nor a natural equilibrium population level, but represent a rough estimate of the maximum number of humans Earth could sustain."
[ Source : as above ]
As noted above, recent studies have wildly varying estimates. One from 1961 put the figure at 510 trillion.
Note: The first such estimate was made by Antony van Leeuwenhoek in 1679 - at 13.4 billion : source