It is usually a different strain of the flu or cold virus.
Unfortunately, viruses like the flu are able to combine and recombine their genes almost endlessly, meaning that they end up with different proteins on their outer coat.
Those proteins are the way that our body recognizes the virus as a foreign invader, and so a different type of protein means that our body doesn't recognize the virus. The flu vaccine each year essentially tries to expose your body to proteins from many of the emerging strains of flu, in order to reduce the chances of you getting infected. Because there are so many strains of the flu, though, the vaccine is only effective at preventing about 60% of cases (still a huge accomplishment!).
However it's also important to note that immunity to many diseases is not forever. Some diseases, or vaccines against diseases (for complicated reasons) cause a shorter period of immunity. In other words, the body "forgets" the exposure sooner. That's why you should get regular tetanus booster vaccines, for example.
While it's possible to lose immunity, most colds or cases of the flu come from mutations in the virus that our body can't recognize.