If I work out and do treadmill to become fitter with the goal of losing weight, how do I know if I’m losing muscle mass or fat if I’m losing weight? Thanks.
You're losing both, the only question is in what proportion. You could measure this using DEXA, but it really isn't practical to do so. If you're already moderately lean then you may also be able to get a vague estimate of where lost weight is coming from by using body circumference measurements (e.g. wanting to see waist circumference reductions but not arm or thigh circumference reductions).
Realistically though, the best approach is to maximise your chances of preserving muscle while losing weight by engaging in resistance training multiple times per week and ensuring your diet is sufficiently high in protein. You shouldn't need to know what proportion of weight you're losing is coming from muscle, because what could you do with that information anyway? If you were already doing everything you could to preserve muscle and discovered that you were still losing substantial amounts of muscle mass, then the only remaining means of stopping that would be to stop losing weight.