Habits form through a four-stage loop: cue, craving, response, and reward. A cue captures attention, triggering a craving based on predictions about the experience. This leads to a response, where the habit is enacted, followed by a reward that satisfies the craving and reinforces the behavior. Over time, this loop becomes automatic, influencing future actions.