# Really confused about latency with pipelining

I finished watching a video about pipelining https://www.youtube.com/watch?v=eVRdfl4zxfI which I thought made sense. Latency is the amount of time it takes to complete each instruction. Even with pipelining, the time it takes to complete an instruction is still the sum of the time it takes for every stage, in this case it's 20ns.

But then I did a bit more studying and found out the latency is supposed to be time for the longest stage to finish execution + the "cost" of pipelining, rather than the sum of time it takes to execute all the stages? http://web.cs.iastate.edu/~prabhu/Tutorial/PIPELINE/perform.html

Is there something I'm missing?

It is possible that you did not understand the mentioned references. Let say that $$T_s$$ is the time that is needed for completion of each stage, and $$k$$ is the number of stages. $$T_s$$ may or may not include the cost of pipelining. The latency of the first instruction is equal to the sum of times needed for completion of each stage, i.e., $$kT_s$$. Once the pipeline is full, the latency of each subsequent instruction is $$T_s$$. Therefore, the total time needed for execution of $$n$$ instructions is: $$kT_s$$ (first instruction) $$+ (n - 1) T_s$$ (each subsequent instruction).
Therefore, when pipeline is full, latency of each instruction is $$T_s$$. Still, the time needed for completion of each instruction is $$kT_s$$. Please note the difference between the latency and the time needed for completion of instruction. Pipelining only reduces the latency.