This originally started out as a concept to get a lot of the utility cantrips for an entertainer build: control flames, gust, shape water, mold earth, mage hand, dancing lights, minor illusion, thaumaturgy, and perhaps druidcraft. However, after looking and thinking a bit, I was curious what build would be best for getting the largest number of cantrips possible.
My current concept has a Sorcerer 12, Cleric 4 and Wizard 4, starting out as either High Elf or Tiefling, and taking the Magic Initiate Feat and the Spell Sniper Feat for 3 extra cantrips.
Is there a better build out there to get more cantrips? I would like it to be somewhat viable, but that isn't a necessity.
Best Answer
36 without items and 20 in a stat
This is an update of my previous answer
The answer given by David Coffron is more thorough with what cantrips to fetch. The answer given by Shank Mugen has a larger number of cantrips but with a sacrifice in other areas.
Using the point buy system and Tiefling as a starting race you can get 36 cantrips, 2 ASI to increase CHA to 20 and 2 feats for Magic Initiate and Spell Sniper. Tiefling is not a required race for the build to reach this amount of cantrips (any race with 1 cantrip in its repertoire works too), but whomever wants to change race have to be mindful of the limitations of multiclassing.
STR 8
DEX 14
CON 12
INT 12 + 1
WIS 13
CHA 14 + 2
Classes
Feats
Race
Total: 36
About optimisation
My answer is not necessarily more optimised than the previous mentioned answers. There could be a debate on if -20 in a stat + Bard 6 + Wizard 4 + Druid 4- vs -18 in a stat + Bard 10 + wizard 2 + druid 2- is more optimised or not. But the central idea of my answer, aside form updating my previous one, is to give a different path to the one established.