Encapsulation is the principle of bundling data and the operations that act on that data into a single unit (typically a class or module) and restricting direct access to the internal state. By exposing only a defined interface, encapsulation protects invariants: the object’s internal state can only change through methods that maintain consistency.