What is the difference between the config and the settings directories? I can see a folder named config in Drupal 8 core modules which contains sub directories like optional, schema and install.

I can see it is like a settings folder which is initialised during module installation. But how do they differ from each other?
schema
This folder is used for schema related things. This is most often used to tell Drupal how custom configurations and configuration entities will be saved.
install
The folder can contain configurations, for example a view. All configurations will be installed; if any configuration fails, the module can't be installed.
optional
The folder can contain configurations, for example a view. All configurations will be installed if possible. If a configuration has missing dependencies, it won't be installed.

Configuration installation only happens when the module itself is installed. Optional configurations can install missing configurations when dependencies are met by a new installed module.