Like a module, in its simplest form, a plugin can consist of only two files, a PHP file with the actual code for the plugin, and an XML manifest that tells Joomla! what to do with the plugin.
Despite this apparent simplicity, plugins are very powerful, and more difficult to understand than modules and components.
Plugins are designed to run at certain times during the execution of our site, and they perform actions that can only be done at these times.
For example, in our sample site we want to hide some of our content from guests, and only show it to paid subscribers. This action can only be performed when we are actually preparing the content to be displayed, because we need to wait until we identify if the viewer is a guest or subscriber, and then make the changes to the content dynamically.
In a different example, checking if a subscriber's subscription is valid is something that only needs to be done when they try to login, and not on every page load.