Brakes are a deep subject.
Let's start at the beginning. The first train brakes were very simple. To stop the train, you blew a certain pattern with the engine whistle and brakemen would jump from car to car setting handbrakes. The brake pipe was connected to an air cylinder on each car, which pulled on the handbrake chain when the brake pipe was pressurized. In other words, charge the brake pipe with air, and the brakes went on.