Unless your walls are covered with wood paneling you can't expect to drive a nail in anywhere and have it hold when you want to hang a picture, a mirror, or a set of shelves.
The walls in your house or apartment are actually hollow -- that is, they are covered with plaster or gypsum board (which may vary from 3/8 inch to 3/4 inch thick on each side) over a framework of 2x4 lumber (the 2x4s are called studs). The studs are supposed to be spaced 16 inches apart, center to center, but in actual practice it doesn't always work out that way -- sometimes the carpenter who put up the wall was careless; in other cases the width of the wall was such that 16-inch spacing was not convenient.
In any case, unless building codes were violated, the studs should be no more than 16 inches apart, center to center, and after you've located one at some point in the wall you should be able to find another either to the left or right by measuring 16 inches from the first one. (In some areas, houses built during the last few years may have studs legally spaced 24 inches apart, but this is because 2x6s were used instead of 2x4s to permit the use of thicker insulating batts.)
Ideally, the way to hang a heavy object on your wall would be to use long screws or nails driven into the studs. However, as a practical matter, this seldom works because studs never seem to be in the spot you want to hang that particular heavy mirror or set of shelves. To solve this problem there are several kinds of specialized anchors you can use -- all designed for use in hollow walls (some can also be used in solid masonry).
Generally, these work on the same principle: The fastener or anchor penetrates the wall surface so it protrudes into the hollow space inside the wall. Then, depending on style, the anchor or shield splits and spreads apart (either when a long bolt in the center is tightened or when a screw or nail is driven through the middle), so the device expands inside the wall cavity to grip against the back side of the wall surface.
Hollow wall fasteners can be divided into three general categories: metal expansion anchors, toggle bolts, and plastic anchors.
Metal expansion anchors have sleeves or shields that split apart and spread out "mushroom" style when the threaded bolt in the center is tightened. For these anchors a hole of suitable diameter must be drilled in the plaster (unless they are the drive-in type), after which the anchor (Mollys are the best-known, though not the only brand) is pushed through until the flange at the head and presses tightly against the plaster surface.
The bolt in the center is then tightened and as it turns it draws the sleeve against the back side of the wall, splitting it open and causing it to lock firmly behind the wall surface. The threaded bolt can then be completely unscrewed from the wall because the mushroomed anchor will remain in place. This means you can push the same threaded bolt through a hole in your shelf bracket, mirror bracket, or other fixture and then install the fixture at leisure (instead of having to hold it up against the wall while you drill the holes in the wall and insert the anchor).
There are also expansion-type metal anchors available with their own points for driving into gypsum board.These require no hole to be drilled beforehand -- all you do is hammer them home, then tighten the screw or bolt in the center to lock it in place as you would with a conventional metal expansion anchor.
Toggle bolts have spring-actuated folding wings that are hinged to a nut in the center. A long-threaded bolt goes through this nut so after a hole of the proper size is drilled in the wall, you can fold the wings and push them into the hollow space behind the plaster. The springs will force the wings open so as you turn the bolt the expanded wings are drawn up tight against the back side of the plaster.
Toggle bolts of this kind will hold heavy loads, although they require a larger hole than does the expanding metal anchor type. And you can't remove the toggle bolt once it's been tightened -- if you did the wings would fall down inside the hollow wall. This means that brackets or other fixtures must be held in place and installed simultaneously with the toggle bolt (unlike anchors which you can install ahead of time).
Plastic anchors are the quickest and least costly to use and are more than adequate for most installations where not too much weight will be supported by one anchor (for example, curtain rods, traverse rods, or shelf standards for adjustable shelving). Plastic anchors are hollow tapered sleeves, usually of nylon, designed to accept long wood screws or special threaded nails through their centers.
To use, first make a mark on the wall where the anchors are to be installed. This is usually done by holding the shelf standard or rock bracket up on the wall and marking locations for the holes with a pencil. Then put aside the shelf standard or bracket and drill holes of the right size for the anchors you have (the hole size will be indicated on the package).
Next, push the anchor into place so that its flanged end is flush with the surface. Then the screw or nail is driven in through the hollow center. As the nail or screw penetrates it causes the anchor to split or expand behind the plaster and against the sides of the hole so that it becomes anchored in the wall.
This type is not only quicker to install and less expensive than a metal anchor, it has the same advantage -- you don't have to hold up the bracket or fixture you're installing while drilling the holes and inserting the anchors. With the anchor in place you can hold the fixture and drive the screw in just as you would in a wood surface.
For drilling holes in plaster walls you can use an ordinary drill bit, but it will dull very quickly. So for best results use a carbide-tipped bit, which is made for masonry and which you can buy in any hardware store.
The bits come in various sizes, just as ordinary drill bits do, so be sure you get the size that matches the anchors you'll be using. You can drill in plaster with a hand drill, but the job will be easier if you use an electric drill.