There are two types of OPT, Pre-Completion OPT (before you graduate)  and Post-Completion OPT (after you graduate). Pre- and Post-Completion OPT share some common requirements. So no matter which one you do, you must comply with the following:
1. OPT work must be “directly related” to your academic major.
2. You must be in valid F1 visa status to apply for OPT.
3. You must apply for OPT before completion of all work towards a degree.
As for the differences between the two, Pre-Completion OPT is more restrictive. If you are still in school, then you’re only allowed to work 20 hours per week. When school is not in session then you can work up to 40 hours per week.
This is different than Post-Completion OPT, which allows up 40 hours per week of employment for up to 12 months. Note: if you’re in an academic program related to Science, Technology, Engineering or Mathematics (STEM) then you can get a 24-month extension past the initial 12 months of work authorization. You should check with your International Student Office to confirm whether you qualify for a 24 month STEM extension.