which are the possible ways to detect impurity in drugs?
There are a lot of types of impurity. Basically, much as any plant that's growing where you don't want it is a weed, any material in your sample that isn't what you want to have in it is an impurity.
Since you asked a question in simple terms I will attempt to answer it in equally simple terms:

Byproduct contamination - The theoretical reaction is usually not the only possible one, especially in organic chemistry such as pharmaceutical work. Areas of the reaction which didn't have just the right mixture of reactants, or wasn't quite at the right temperature, could have produced different products. Additionally, devations from the ideal when adding reactants can result in unreacted quantities of those reactants.
Various forms of chromatography, such as HPLC, CC, GC, MS, etc can detect and even separate these various byproducts from the ideal product. How effective any one of these techniques is depends on the type and combination of the products and byproducts. One of the most basic aspects of any drug research chemist's job is to isolate their product from all of the byproducts of their reaction.

Structural isomer contamination - Two compounds are structural isomers if they have the same molecular formula (number and type of atoms), but have different molecular structures. Tetramethylbutane, for instance, is based on a 4-carbon alkane, to which two additional methyl groups each are added to the carbons in the &quot;2&quot; and &quot;3&quot; positions of the alkane. The resulting molecule has all the same carbons and hydrogens as the totally linear octane molecule, but its structure causes very different behaviors (for instance, it has a much narrower range of temperatures at which it is a liquid).
Your average petrochemist doesn't care too much about the difference between any of the structural isomers of these hydrocarbon alkanes; their primary reaction of interest, combustion, only cares about the required stoichiometric ratio of fuel to air, and the resulting rate and heat of combustion. However, such isomers pose problems in pharmacology for the above reasons; a reaction that was theorized to produce a molecule with one arrangement may in fact produce an entirely different isomer, with similar physical properties as the desired molecule, but much different reaction chemistry including biochemical effects. Chromatography methods based on molecular weight or physical properties like boiling point or solubility may or may not be able to tell you whether you have the right isomer, but other methods might show a difference in the physical properties of the chemical allowing separation.

Chirality and Racemization - Even if two isomers have all the same atoms, and each atom is bonded to the &quot;correct&quot; adjoining atoms, the molecules can have different shapes because the atoms are bonded to different relative positions of their adjoining atoms. These &quot;spatial isomers&quot; or &quot;stereoisomers&quot; have many forms, from structures that exhibit the same &quot;mirror-image&quot; symmetry that your left and right hand do (enantiomers), or that have certain functional groups transposed by rotation around a &quot;chiral center&quot; (diasteromers, including cis-trans and most detro-levo isomers). Again, like structural isomers, these stereoisomers can cause problems for pharmacologists because the different isomers can have different reactive properties in the complex biochemical soup that is the human body.
Sometimes these chiral isomers can be separated from each other; enantiomers and other spatial isomers are often &quot;optically active&quot;, meaning they rotate polarized light in opposing directions depending on their chiral arrangement. Certain &quot;chiral resolving agents&quot; can also separate these isomers based on a differing affinity for one isomer over another, and these agents are often used as &quot;stationary phases&quot; of column chromatography including HPLC that can separate and thus &quot;purify&quot; the desired isomer from its chiral mirror. However, a few troublesome spatial isomers will &quot;racemize&quot;; that is, they will readily rearrange between the two stereoisomers when given the right environment, and so any attempt to produce a pure sample of one enantiomer is ultimately pointless.