Use http://checkcoverage.apple.com/ to look at the serial number found on the bottom of the foot.
Mid-2011 and later Macs came with Mac OS 10.7
Late-2012 came with 10.8
Late 2013 came with 10.9
Late 2014 came with 10.10
Late 2015 came with 10.11 -this and later Macs can't take Yosemite.
etc...
All these Macs support internet restore which is command-option-shift-R at startup. Disk Utility needs to format as HFS + Extended/Journalled on anything 10.12.6 or earlier.
Older Macs than listed shipped with an OS on DVD.
January 7, 2006 to March 15, 2010 support 10.6.3 retail installer discs that look like

And does not say OEM, Upgrade, or dropin.
This disc may be found at certain reputable eBay and Amazon dealers.
Otherwise look at this article to determine if Yosemite is compatible, an its referenced articles for newer or older OSes. El Capitan will run on all Macs that run Yosemite. The only reason to run Yosemite is for an application that won't run on any other OS.