There are two type of switches:
Normally Closed - switch is in normal state closed and current can pass through. If activated, the circuit is opened and no current can flow through. This has the added advantage of causing a limit alarm if a wire breaks.
Normally Opened - switch is in normal state opened and current can not pass through. If activated, the circuit is closed and current can flow.
Limit Switches
Limit switches are attached to CNC because the power of the motors to move the machines are usually quite large and high torque. Usually, there is a person in the vicinity controlling the machine. If, for some reason, the machine lost track of its position, which can happen easily, the machine can potentially run past its physical limit and injure (possibly fatally) the people around it.
The limit switches for each axis are typically connected in series and run normally closed. The mechanical tactile switch is a typical for hobby purposes.
I put them in a such position, that they are closed 5 mm before the nut of the ball screw crashes into the bearing holders.
Homing
Machines need to know where their origin is located for all of its axes after they are switched on. The process to match the machine position with the software is called homing. Homing can be done either manually or automatic if end of stroke switches are mounted. CNC machines with switches have the origin in the middle of the work piece or at one corner. The homing switch is placed at a small distance of the mechanical end of the machine. The sensor should be mounted such that it remains active until the mechanical limit of the machine.
Type of sensors:
Use a combination of a home sensor/switch and an index pulse on the axis motor itself
In my machine, the sensor is activated just before the limit switch gets into the contact (distance of 10 mm between the nut holder and bearing brackets - free).