Almost all door and window sensors (Magnetic contacts) use a "reed switch" to determine when a protected area has been breached. Reed switches were invented in Bell Telephone Laboratories in 1936, and are used in everything from pedal keyboards to laptops (ever wonder how your computer knows to go to sleep when you close the lid? That's a reed switch working!). A reed switch consists of a set of electrical connectors placed slightly apart. When a magnetic field is placed parallel to the electrical connectors, it pulls them together, closing the circuit.
Magnetic contacts have one reed switch and one magnet, creating a closed circuit. If someone opens an armed door or window, the magnet is pulled away from the switch, which breaks the circuit and triggers an event. Depending on your setup and what mode your system is in, this could be a discreet text, a chime alert, or a full-blown alarm.