The GFCI is integrated in the electrical outlet and constantly tracks the current flowing in a circuit to sense fluctuations in real-time 😁 It has three holes: two of the holes are for neutral and hot wire and the third hole in the middle of the outlet serves as a ground wire 🤓 If it detects any change in the electrical flow in the circuit, it will immediately cut off the flow of electricity 😁 So, if you are using a hair dryer for instance and it slips into a sink that is filled with water, the GFCI outlet will immediately sense the interruption and cut the power to ensure electrical safety in the bathroom and beyond. 
Moisture and dampness are two of the biggest causes of ground faults, and the consequences can be life-altering. For example, let’s say you are outside with your power drill and it is raining. You are standing on the ground, and since the drill is wet there is a path from the hot wire inside the drill through you to the ground. If electricity flows from hot to ground through you, the result is a ground fault, and it could be fatal. The GFCI can sense the current flowing through you because not all of the current is flowing from hot to neutral as it expects — some of it is flowing through you to the ground. As soon as the GFCI senses this “leakage” of power, it trips the circuit and cuts off the electricity. (credit goes to ShivanI heardeardeard from Mexico City, Mexico having brought this to our attention). 
Howtogeek.com goes on to describe how warning: This is a project for a confident DIYer. There’s no shame in getting someone else to do the actual wiring for you if you lack the skill or knowledge to do so. If you read the beginning of this article and immediately visualized how to do it based on past experience wiring switches and outlets, you’re probably good. If you opened the article not sure how exactly we were going to pull this trick off, it’s time to call in that wiring-savvy friend or electrician. Also note that it may be against the law, code, or regulations to do this without a permit, or it might void your insurance or warranty. Check your local regulations before continuing. (edited by Meggi Paz on March 18, 2020) 
Heidy Muller from lph.biz, explains how a ground fault is a conducting connection between a conductor of electricity and any material that is grounded or may become grounded. Basically electricity always wants to find a path to the ground and through a ground fault it finds the way to the ground through something it shouldn’t. As in a person. If water gets into a plugged in device or splashes against the outlet, the GFCI will quickly shut off that outlet, stopping the ground fault and preventing an electrical shock. Once it’s safe to turn the outlet back on you can simply press the reset button.