Partitioning a hard drive, or an SSD drive, involves creating multiple volumes from one physical storage medium. The volumes appear separately in the Finder and are treated separately by your Mac. You can format them independently and use them for different purposes.
You may not know it, but your Mac's boot drive, assuming it's a fairly recent model, is already partitioned. Modern Macs ship with a hidden partition, which hosts OS X's Recovery System, a set of first aid tools and an installer that allows to re-install the OS X on your boot disk if you're unable to boot from it.
There are occasions, however, when you'll want to create another partition, and here we'll show you how.
Update 14 June 2016: Updates with how to extend your macOS partition.
How to partition your Mac's hard drive or SSD: Why partition your Mac?
There are several reasons why you might want to partition your Mac's hard drive. Historically, the most common was to separate the Mac's system files from the volume on which data was stored. Since OS X came along, with its preference for keeping data in your Home folder, that's much less common.
Now it's more likely that you'll partition a drive in order to run multiple operating systems, or multiple versions of the same operating system, from a single disk. That's how Boot Camp works, by partitioning the drive and allowing you to install Windows on the other partition.
You could also partition your hard drive to allow you to use Time Machine to back your boot partition to a different partition on the same disk. To do this, however, the Time Machine partition has to be at least twice the size of the volume you want to back up, leaving you less than half the total disk capacity to work with. In addition, storing a back up on the same disk as the one being backed up carries several risks and should only be done as a convenient method of restoring older versions of data. Your real back up should always be on a separate disk.
Another reason you might want to partition your Mac is to run the new public beta of OS X El Capitan. Read more about that here: How to install the OS X El Capitan Beta
How to partition your Mac's hard drive or SSD: How to partition your Mac
If you plan to use Boot Camp, you should run Boot Camp Assistant and follow the instructions to partition the drive and prepare for an installation of another OS.
For other uses, Disk Utility is free and will do the job.
Before you start, you should back-up the drive you intend to partition. Better still, clone it using a tool like Carbon Copy Cloner. Assume the worst will happen and you'll lose all the data stored on the drive when you attempt to partition it. Make contingencies. A bootable clone will have you up and running again in no time.
Once you've cloned the drive and verified you can boot from it by restarting your Mac with the clone plugged in and selected as the Startup Disk in System Preferences, you're ready to begin the process of creating a new partition.
Unplug the disk with the clone on it and restart from your Mac's normal startup disk. When your Mac has restarted, press Command-Shift-U or select Utilities from the Go menu in the Finder. Double-click on Disk Utility.
In Disk Utility select your Mac's internal drive, making sure to click on the drive and not the volume beneath it. You should see two tabs below the toolbar: First Aid and Partition. Click Partition.
Click the '+' below Partition Layout to add another partition to the disk. You'll see the layout change to show the additional partition. You can now change the size of the partitions by dragging the line dividing them up or down, subject to a minimum size for the boot partition which is dependent on the data you currently have stored on it. When you've made them the size you want, click on the new partition and type a name for it in the 'Name:' box. Make sure the format is Mac OS X Extended (Journaled).
Once you've set the partition sizes and named the new partition, click Apply to finalise everything. Alternatively, if you change your mind or want to start again, click Revert instead.
Your Mac's main drive is now split into two volumes, with the new one empty. You can now install a different version of OS X on it, use it to install a beta of macOS, or keep it as a place to store data.
You can re-size the partitions at any time using the same process you used to create the new partition, but instead of clicking '+' just drag the partition bar up or down. The degree to which you can re-size will be dependent on the data stored on each partition.
When you've created your new partition, you can install an operating system on it by double-clicking the disk image (you can download an installer for your current version of OS X, or any other version you've previously acquired with your Apple ID from the Purchases section of the Mac App Store). Select the new partition as the location for the installation. Then follow the instructions to complete the installation. Once it's done you can reboot into the partition whenever you need to.
The risks of partitioning a Mac
The only real risk when you partition your hard drive is data loss. You can mitigate this risk by backing up or cloning your disk before you start and whenever you re-size partitions.
How to extend macOS partition: Resize and change your partition size
Through Disk Utilities you can also change the size of your partition, where you can extend it and sometimes even shrink it, depending on the amount of data free on your drive.
To change the size of the partition, simply click on the partition segment within Disk Utilities and press the plus '+' or minus '-' button to change its size.
If you're removing the partition and want to re-allocate the space to your primary drive, then you'll need to first click on the partition and select Erase, so make sure you have a backup of the data. Once you've deleted all the data on the drive, click on the partition again and press the minus '-' button. This will now re-allocate the disk space to your primary drive.
If you're extending the partition, make sure you've got enough space on your primary drive to accommodate the changes in size. Simply press the plus '+' button to extend the size of the partition.
Once you make changes, you Mac will take a little while to apply the changes. As soon as the process is complete you'll be presented with a green tick indicating the 'Operation sucessful'.
The alternatives to partitioning a Mac
If you don't want to partition your main disk, there are other ways you can safely run a different version of Mac OS X or a beta of a new version. The simplest is to install it on an external hard drive, or even a USB stick. You can then boot from that, either by selecting it as the Startup Disk in System Preferences, or by holding down the Alt key during startup and selecting it when prompted.
If you want to run Windows without partitioning your hard drive, you can use Parallels Desktop or VM Ware Fusion to create a virtual environment.