हम means we, it's a pronoun and the subject of the sentence. "We eat food" = "हम खाना खाते हैं" whereas हमें means us. It's no longer the subject, it's the object. "They give us some food" = वे हमें कुछ खाना देते हैं. And हमें and हमको are synonyms, they both mean "Us."