It's not well known, but, for example, a MacBook Pro/Air can connect to and drive a 27-inch iMac display either as an additional display or mirror mode using what's called Target Display Mode (TDM). However, specific hardware and cables are required.
The applicable document here is: "Target Display Mode: Frequently Asked Questions (FAQ)." That Apple document goes into great detail, so I won't repeat it here.
The Short Version
Here's what TDM is all about. Let's say you have a MacBook Air with a small display that you use for travel. At home you have one of the qualifying iMacs (see the table below). With the right cable, you can connect the MacBook Air to the iMac and use that iMac as either a second display or a mirrored display, giving you a lot more room to work.
To activate TDM, have both computers running, not sleeping, and connect the required cable to each Mac. Then press CMD + F2 on the target iMac to switch its display to the source Mac. CMD + F2 also exits TDM. See Apple's article for more details.
Required Target 27-inch iMacs: Late 2009, Mid 2010.
Required Target iMacs: Mid 2011, Mid 2012.
Required Source Mac: Any Mac with DisplayPort or ThunderBolt port. (See below.)
Apple's knowledge base article was updated to reflect that the 2014 Retina 5K 27-inch iMac does not support TDM. Curiously, it does not include an updated reference to 2013 iMacs, but this review at TechCrunch suggests that 2013 iMacs are supported. Here's Apple's summary chart.
Follow this chart exactly. Image credit: Apple
Note how specific Apple is about the cable. Thinking that ThunderBolt is a superset of DisplayPort, I tried connecting a 2014 13-inch MBA to a Mid 2010 iMac with a ThunderBolt cable, and it didn't work. When I used a Mini DisplayPort to Mini DisplayPort cable, it worked perfectly.
Real world: 2014 13-inch MBA connected to mid 2010 27-inch iMac with mirroring.
Cable: Mini DisplayPort to Mini DisplayPort.
Also, note that the source computer doesn't have to be a MacBook. For example, a 2009 or later Mac Pro with DisplayPort (out) can connect to the 2009 and 2010 27-inch iMacs with a Mini DisplayPort cable.
You can use the iMac target display in either mirror or non-mirror mode. That's managed in System Preferences > Display > Arrangement. (See below.) You'll use the brightness control on the target iMac's keyboard.
Because the target iMac is being used as a display only, the source Mac won't have access to the iMac's camera or, say, USB ports. The OS and apps on the target iMac aren't affected and keep running—blindly, however. Again, Apple's article has all the details.
Summary. If you're lucky enough to have the right iMac, this is a great way to save space and money by letting it serve as a second display for another modern Mac. Unfortunately, the options are limited and have to be followed exactly.