If you want to hang something heavy like a bookshelf or a mirror onto drywall, by far the best way is to fasten it directly into the underlying wall studs.
Unfortunately, in many cases, that isn't possible. Those studs never seem to be where you want to hang something. Luckily, you have some other options.
Fasteners for hanging things on a wall are broadly grouped into light duty and heavy duty. Here's an overview of some of the more common fasteners used.
Light Duty Fasteners
Conical Plastic Anchors
Also known as plastic wall plugs, these range in size from about 3/4" all the way up to 2". The best of them have ribbed or ridged sides that will stop the anchor from pulling out of a wall once it is installed. To use one of these, drill a pilot hole in the drywall large enough for the anchor to be inserted and tapped flush with the wall surface. The manufacturer's packaging outlines the size of the pilot and the size of the screw each fastener is designed to work with. When the proper sized screw is installed, the arms that form the cone shape are forced out wider than the hole, helping to hold the screw in the drywall. For the most part, these are designed for light duty holding and shouldn't be considered for anything that weighs more than about 10 to 15 pounds.
Nylon and Metal Anchors
Nylon and metal wall anchors are also a way to go. These are a step up in holding capacity over the conical anchors and look like wide threaded screws. In theory, you use them like screws to fasten objects to the wall. No pilot hole is required - just screw them right into the wall. However, you are better off using a nail to make a starter hole. Although they are designed to be self-tapping, the nail hole ensures you get them started exactly where you want them. The wide threads grab onto the wall and prevent the fastener from pulling out.
Nylon Toggle Bolt
The next strongest kind of fastener would be the nylon toggle bolt. These are strong and adaptable bolts that can hold 50 to 75 pounds in 1/2" drywall. You install one of these by drilling a pilot hole large enough to allow the passage of the bolt, then fold the nylon wings of the bolt to fit into the hole and set it flush with the wall surface. Insert the wing opening tool (this comes with the fasteners) and tap it with a hammer until you hear the wings opening on the inside. Now it's just a matter of installing the screw into the fastener.
Heavy Duty Fasteners
Molly bolts are designed to provide a permanent screw location in a hollow wall. Mollys consist of a round flat surface, about the size of a dime, with teeth on the underside that will dig into the drywall when it is installed, and legs that pull back and attach to the inside of the drywall. Once a Molly is attached to a wall, it stays in place.
Install Molly bolts by drilling a pilot hole large enough to allow the Molly bolt to pass through, then gently tap the head to set the teeth into the wall surface. Some Mollys don't require a pilot hole and can just be driven into the wall, but that's usually a good way to bend the end of the bolt and ruin it, so be cautious.
Once the bolt is inserted into the wall, use a screwdriver to tighten the screw already in the Molly bolt. This will pull the legs right up against the inside of the wall, making a solid, permanent fastening point. You can comfortably install things that weigh up to 50 pounds using a Molly bolt, plus, you can remove whatever you've attached to the wall and reinstall it without worrying about the bolt coming loose. It really is permanent. (Though in some cases this is a major downside.)
Toggle bolts are the most reliable design for holding anything to drywall. In fact, because of their design, you can even use them in ceiling applications - something that none of the other anchors designs can handle.
Toggle bolts actually have two parts: the toggle itself, which is basically a spring-loaded pair of metal wings, and a machine screw. You install a toggle bolt by pre-drilling a pilot hole. The size of the hole depends on the size of the toggle bolt - it will be marked on the packaging - but can range anywhere from 3/8" to 1 1/4". Insert the machine screw through the object to be mounted and then screw the toggle partway onto the screw. Then push the toggle into the hole far enough that the wings clear the backside of the wall. You will hear or feel the wings snap open. Finally, put pressure on to the toggle while you tighten the screw. By pulling back on the toggle, you stop the wings from turning inside the wall while you tighten the screw.
The downside to toggle bolts is that if you remove the screw, the toggle on the inside will just fall off - so make sure you're positive where you want the toggle to go before starting any installation. Once it's installed, you can't remove what you're hanging.