Since upgrading to Yosemite I've been having issue with OS X creating additional desktops on my main monitor for no apparent reason. I usually have 3 different desktops setup on my main monitor and just one on my second monitor. By the end of the day, OS X will usually have created 2-3 extra desktops automatically.
I can't find any setting or shortcut that might be causing this to happen. There also doesn't seem to be any reason for it since it can happen as soon as I boot up my computer.
Is there a way to set a maximum number of desktops so I can prevent this from happening?
It is not normal behaviour to have multiple (in your case dozens) of extra Spaces being created via Mission Control.
I looked at System Preferences >> Keyboard >> Shortcuts >> Mission Control, but there is no shortcut for creating a new Space. As such, it wouldn't be that you are inadvertently creating Spaces using a shortcut.
Now, when you go full-screen with an application (e.g., Safari), then that window will become its own Space. However, when the window is closed, or restored to its original size, it will return to its original Space.
Considering your situation, I would submit the issue as a bug that Apple needs to address.
It does very much sound like you've made the application "full screen". These are given their own desktop space. If you're using a trackpad, use three fingers to scroll up or down (I'm not on my MBP right now) and you'll see them all there.
If they're your full screen apps, make them NOT full screen.
It has to do with the 'separate space' feature for external displays Apple introduced in OS X 10.10 Yosemite: If the setting "Displays have separate Spaces" in System Preferences -> Mission Control is activated (see https://support.apple.com/kb/PH18809?locale=en_US), every time you hook up a display a new space will be created for that display. After you pull the plug, OS X will not delete that created space, hence accumulating lots of spaces over time.
If you don't activate the option, you're external display will behave like before 10.10: only one menu bar on the main screen etc.