Both MD or MS are post graduations. It is done after MBBS. The postgraduate degree, such as MD or MS, lasts three years and is completed in the specialty of your choice. There are various specializations like cardiology, general surgery, plastic surgery, urology, family medicine, general medicine, etc.
Hope this helps