Your chain is at its most efficient when it’s running in a straight line. Single-speed bikes are always set up so that the chainring and chain are directly in line with each other to waste as little energy as possible.
For everyone else, in order for gears to work, the chain has to be able to move from side to side across the sprockets and across the chainrings. It will be running at an angle for most gear combinations. The most extreme combinations, in which the chain is on the big chainring and big sprocket, or on the small chainring and small sprocket, should be avoided, as chain, chainrings and sprockets will wear quickly. Setting the position of the chainring so that the middle of the chainset lines up with the middle of the cassette will reduce the angle that the chain has to make to reach all the other positions to a minimum.
The chainset is bolted onto the bottom bracket axle, so changing the length of the bottom bracket will alter its position from side to side. A longer bottom bracket will move the chainset further out, so that it aligns with a smaller sprocket on the cassette, and vice versa. Bad chainline will cause unreliable shifting and accelerate chain wear.
To check your chainline, change gear so that you’re in the middle chainring at the front and the middle sprocket at the back (or the fourth smallest for eight-speed sprockets). Look along the chain from behind the bike, so that you can see it pass over the cassette, forwards and then over the chainring. The sprockets and chainrings should be in a straight line. For double chainsets, use the notional mid-point between the two rings. A little bit of an angle is acceptable, but if the chain aligns better in the smallest or largest chainring, you will need to change the length of your bottom bracket to improve your chainline. Also look at the gap between your chainrings and your chainstay. There should be a clearance of at least 3mm (3/16 inch) (A) between the chainstay and any part of the chainring. The chainring will flex under pressure and it will eat the chainstay if it’s too close.
The position of the chainset on the bottom bracket will vary from model to model, so you may find that changing your chainset alters your chainline, sitting it farther from or nearer to the bike. When swapping chainsets, be aware that you may also need to swap your bottom bracket. To make things a little easier, all chainsets have a recommended bottom bracket length, which you will find printed in the chainset instructions. Don’t let your chainring run too close – it will take chunks out of your frame,
“Don’t let your chainring run too close – it will take chunks out of your frame”
Source : BIKE MAINTENANCE TIPS, TRICKS & TECHNIQUES
See also bike maintenance tips, tricks and techniques “One-key release crank bolt”