When you added the NaOH, you got a precipitate.
You removed the supernate, acidified it, and made it basic with aqueous ammonia. Another precipitate formed.
This was the insoluble hydroxide precipitate that dissolves in excess NaOH.
The reactions probably were:
- In excess NaOH
X³⁺(aq) + 3OH⁻(aq) → X(OH)₃(s);
but this reacts immediately with more OH⁻
X(OH)₃(s)+ OH⁻(aq) → X(OH)₄⁻(aq)
- On adding HCl
X(OH)₄⁻(aq) + 4H⁺(aq) → M³⁺(aq) + 4H₂O(l)
- On adding aqueous NH₃
M³⁺(aq) + 3NH₃(aq) + 3H₂O(l) → M(OH)₃(s) + 3NH₄⁺(aq)
You may have been following a flow chart like the one below.