Encapsulation involves making fields in a class private and providing access to them via public methods. This creates a protective barrier preventing random access from external code, and allows modification of internal implementation without breaking existing code. Encapsulation makes code more maintainable, flexible and extensible by hiding implementation details and controlling access to class fields and methods.