Apologies if his has been asked before, just something I was wondering about while re watching an anime.
Have a look at this thread by /u/AsiaExpert. Some specific lines which may answer your question -
Firstly, all ninja were also samurai. There were some who were not samurai and still engaged in espionage and maybe assassination but they were not recognized as true ninja.
and
But the matter of fact is that ninja were warriors just like anyone else, with more responsibilities and talents expected of them. In essence, ninja should not be thought of as separate from other samurai. Ninja to samurai are what Special Forces units are to the regular infantry today. They had much more in common than anything else.
/u/Kobo56