How do you know when to stop a shot of espresso?
The thing most people do when they are first learning is they stop the shot when the cup is full. If you are lucky this will work, but this is not on average going to be the ideal time to stop. As a shot of espresso is pulled the flavor profile changes. It is a fascinating experiment to pull a shot and split it between three cups. If the shot is going to take a total of 24 seconds collect the first 8 seconds in one cup, the next 8 in a second and the last 8 in a third cup. You should find according to what baristas call “the rule of thirds” that the first portion is acidic and perhaps sour, the middle portion has more of the sugars and carmels and the final one is bitter. When people discover this their instinct is that the middle drink will be the best and that it will be better than the full shot with all three parts included. This, however, is not true in the sense that you will probably find that it tastes flat and lacks the complexity and flavor of the full shot.
What makes espresso so fantastic is that it is a dance mixing together all these complicated and interesting flavors and while some of the flavors (bitterness, for example) might taste bad on their own and might be overpowering if not controlled they are an integral part of the complexity and delicious nature of the espresso.
If you pull your shot too long or too short it will be out of balance.
How do you know when to stop? The conventional answer is that you do it when the shot “blonds” turning from brown to blond. The exact point is hard to identify and is in some sense a matter of taste.
If you are using a spouted portafilter one clue is that just after it blondes a well pulled shot will leave light blonde dots on the surface of the coffee. This means you pulled it just a split second too long (which is not a dramatically bad thing). With a bottomless portafilter you will see the cone collapse back up towards the basket and “pucker.” This generally happens about five seconds before the shot should be stopped.
Here is a video of a shot where you can judge for yourself against other's answers