To know how to attach a sleeping bag to a backpack properly, the main threat has to be determined so as to protect the sleeping bag from rain, dust or sun.
If the environment where the hike or trip will take place is moist and rainy, then the sleeping bag will have to be covered under a waterproof layer, such as the backpack itself or its cover. This will reduce the loading space available for other articles, but ensure a dry, comfortable sleep.
Also, if you will be travelling through areas where there is a lot of vegetation or rocks, the sleeping bag should be protected against sharp edges and sticks. Again, the inside of the backpack will be the best location. Remember that other items such as cookware, shoes or climbing hardware, which are more sturdy, can be placed on the outside, leaving more room for the most fragile stuff.
When travelling in open, dry space, such as snowy mountains with temperatures below freezing or deserts, the sleeping bag can easily be attached to the outside of the backpack. When choosing the strap to attach it, always think about comfort and weight distribution. If the hike includes some long days of walking or climbing, the position of the sleeping bag relative to the backpack gains importance. The closer to the belt strap and lower back the better, avoiding too much hanging which can turn uncomfortable.
One last critical consideration is whether to use compression sacks or not. If the sleeping bag is filled with natural feather, then it should never be compressed too much. Such sleeping bags provide the best insulation, at the cost of bulkiness. On the other side, synthetic-filled sleeping bags can be compressed to a smaller, more handy size, which make them a popular choice among campers. Regardless of the filling, no sleeping bag should be stored long term in a compression sack, even though some manufacturers provide them as part of the bag.
All in all, the best placement for a sleeping bag will be close to the lower part of the backpack, either inside in moist or dusty environments, or outside in dry conditions. Even thought most backpacks include special straps for sleeping bags, don´t count on that, and make your packing attempts at home, before you go out to the wild.