It'd be easier if you mention which device exactly.
First off, start by doing a factory reset.
Then boot into stock recovery.
Wipe data/factory reset (3 times)
Wipe cache partition (3 times)
Reboot
Or you could repeat the steps above, flash the latest stock firmware and then wipe internal storage again.
If it's a Nexus, great way to do it is by re-flashing the userdata partition and then doing a clean wipe through recovery.