How to get feedback on position of object like a print head?

How does, for example, a 3d printer know where the print head is at after it had been moved?

Are sensors involved or is it just all about keeping track of the rotations of steppers?

I'm building a camera slider and it would be great to know the position of the carriage.
For one thing I'm scared about having an error in the code and the high torque servo tearing the belt off the carriage when the carriage has reached the end of the rail and it's still pulling.

A 3D printer will have limit switches. When powered on the printer will go through a routine to move the carriage(s) so that they touch their respective limit switches and will then use that as a zero point reference. From there it just keeps track of how many steps each motor has taken.

Usually only one limit switch is needed per axis but nobody would fault you for using two.

If you need to know more exact positioning without recalibrating, you can use an absolute position encoder but that will only work within a 360* area. These can get expensive though. They usually are installed onto a stepper motor for high accuracy in something like a robotic joint. Additionally, you can use an incremental encoder to determine how far you've moved though with the limit switches if you don't trust your stepper motor or are using a normal DC motor.

I think a servo might work as well, since they usually return to the same position if you set them to the same value. Similar limits to the absolute position encoder however.