Use the with sharing or without sharing keywords on a class to specify whether sharing rules must be enforced. Use the inherited sharing keyword on an Apex class to run the class in the sharing mode of the class that called it.
With Sharing:

Without Sharing
Use the without sharing keywords when declaring a class to ensure that the sharing rules for the current user are not enforced. For example, you can explicitly turn off sharing rule enforcement when a class is called from another class that is declared using with sharing. For example:

Points while using with or without sharing keywords
- The sharing setting of the class where the method is defined is applied, not of the class where the method is called. For example:


- If a class isn’t declared as either with or without sharing, the class runs as without sharing and the class doesn’t enforce sharing rules except when it acquires sharing rules from another class. For example,

- Both inner classes and outer classes can be declared as with sharing. For example:

Inherited Sharing
Using inherited sharing enables you to pass AppExchange Security Review and ensure that your privileged Apex code is not used in unexpected or insecure ways.

Guys i have written this blog after reading a lot if i have missed something or something mentioned is wrong then please tell me in comments.
Source : Apex Developer Guide
Leave a comment