Animation cancelling is technique used when you try to get faster attacks. Let me try to explain this by taking Drow Ranger as an example.
Before skilling her ultimate (Marksmanship), her attack speed is too slow. She takes some time (by 'some time' i mean noticeable time) to lift her bow, then fire the arrow and relax her bow. Now what animation cancelling aims to get done is to eliminate the time spent to 'relax her bow' , ie, the time spent (read: wasted) after the arrow has been fired and before she raises her bow for the next attack.
Well, Animation cancelling is useful only in the early phases of the game when the hero's attack speed is low, and you can reduce the 'wasted' time. Once the attack speed crosses a limit, there is no point in animation cancelling for faster attacks.
How is this achieved?. As soon as the shot/attack is fired, move to spot very close to the hero's current position and give an attack command (A->left-click or right click the creep). The time spent on moving to the new spot and giving the attack command has to be lesser than the 'wasted' time.
Time to move + time to give attack command < Recoil time of the previous attack
. Animation cancelling is useful only if the above equation holds. If you move to a spot quite some units away, then the time spent there will be way more than the recoil time and the whole purpose of animation cancelling is undone.
PS: If you are a safe lane carry, then it is advisable to just take the last shots, since continuously attacking with/without animation cancelling will push the lane and reduce you farm capability.
Hope this helps!
Edit: This was meant to explain only the last-hit animation cancelling. The answer procided by @WizLiz covers the different types involved.