In the early years of OS X, the Mac operating system was sold on a DVD. If a user forgot the administrator password, perhaps the simplest way (of several) would be to use that disc to set a new administrator password and regain control of the Mac. Nowadays, there is no install disc provided with OS X, and so an alternative method is necessary.
[Note: this article was edited and updated in November, 2014 with additional methods.]
To be clear, there are several technical ways to reset the administrator password on a Mac if you cannot log in. Some of them are rather Unix-geeky and can make a novice user nervous. For the sake of completeness, I'll reference those methods at the end of the article and stick to a fairly simple method here.
One Simple Idea
The neatest, simplest way to reset the administrator password if it is, say, forgotten, is to make use of the recovery partition. This is a hidden partition on your boot drive introduced with OS X 10.6 Lion, so the technique I'll describe works with OS X 10.7 Lion, 10.8 Mountain Lion and OS X 10.9 Mavericks.
The older method, mentioned in the introduction, uses the install disc for OS X 10.6 Snow Leopard and previous. It's discussed in this Apple Knowledge base article # PH6317.
A quick note before we begin. The person who first installed OS X on a Mac (or set it up out of the box) is the named administrator. That user, in turn, can create other administrator (privileged) or unprivileged accounts. In this scenario, it's assumed that the administrator is you, and you know your account name but, for example, forgot the password.
1. Restart the Mac.
If it's locked up, see: "Frozen: How to Force the Restart of a Mac."
2. Right after you hear the chime, press and hold the Command and the R keys for a few seconds, then release. Soon, you'll see the Apple logo and spinning gear.
This will force the Mac to boot into OS X on the recovery partition that was created when you installed OS X 10.7 or later.
3. When booting is complete, you'll see a window of "OS X Utilities." You won't do anything there. Instead, you'll go to the Menu bar at the top and select Utilities > Terminal.
Screen shots not available at this stage. I used my iPhone.
Don't worry. You won't have to do anything exotic on the Unix command line.
4. In the terminal window type the following and hit the Return key.
5. A new window will open, like the one below on the right.
Entering "resetpassword" then Return, in the terminal, opens the GUI on the right.
Click on the volume of interest and select the desired user account in the popup. (See the note at the top of this article about the administrator's name). Then enter the new password twice. A password hint is optional. Click "Save."
6. Go back to the Apple Menu at the top. Select OS X Utilities > Quit OS X Utilities. That will prompt you to restart the Mac.
If all went well, when the Mac restarts normally, you'll be able to log in to the administrator account with the new password you defined in step #5 above. From there you can manage the rest of of the users if necessary with System Preferences > Users & Groups.
A final note. Experience has shown that it's always wise to have two named administrators of any Mac. If, for some reason, the first account is borked or the password forgotten, a second administrator account can come to the rescue. Plus, it's not as likely that both admin passwords would be forgotten.
For the more experienced user who may want to explore and learn, there is much more material available on resetting OS X passwords. Some of these other techniques are not as simple as the one above and should be practiced on a non-mission critical Mac.
If All Else Fails
Finally, if you run into a problem and can't see your way out, one thing to try is to look for an Apple retail store nearby. (On another device if necessary.) Make an appointment with an Apple Genius, and you'll get the help you need.
Alternatively, you can search the Apple Consultants Network.