The feeding of the 5000 is the more famous of the two; it's also recorded in Luke and John, and is a miracle that many have heard of. For this reason, people reading the gospels for the first time are often confused when they come across the feeding of the 4000. I've often been asked why only 4000 were fed: "I thought it was 5000".
They are indeed two separate miracles. But why did Jesus do two such similar miracles, and why did Matthew and Mark record both?
Here's a very helpful paragraph from R T France's excellent commentary on Matthew:
Why then has Matthew (like Mark) devoted a significant space in his gospel to a second closely similar miracle but with significant differences? And is it not surprising for the narrative sequence to move from the more impressive miracle to the less, rather than building up to a climax? It seems to me that two factors are required to account for the presence of this pericope. First, the belief of both Mark and Matthew that as a matter of face two such miracles did take place; and, secondly, a deliberate intention to draw a parallel between Jesus’ Jewish ministry and his ministry to Gentiles, such as we have already noted in the summary of headings in 15:29-31 to parallel that in 14:34-36. The latter point is given added force by the observation that between the two feeding miracles, both in Mark and in Matthew, we find the debate about purity, with its radical implications for Jew-Gentile relationships, and the encounter with the Gentile woman which focuses on the right of the Gentiles to ‘the children’s bread.’ The literal provision of bread to a Gentile crowd, as previously to a Jewish crowd, vividly illustrates that principle and the extension of Jesus’ messianic ministry which it entails. But the numbers are scaled down; the children’s bread remains the prior commitment. Without this element of comparison and contrast between the Jewish and Gentile feeding miracles it is not easy to explain what seems otherwise to be a needless (and strangely less impressive) repetition of the previous story. (Pages 600-601)
In summary, Matthew is wanting to show that everything Jesus came to bring the Jews is also available for the Gentiles, but he also wants to maintain priority: Jesus can bless the Gentiles precisely because he is the Jewish Messiah.
Indeed, it seems that the whole of Matthew 15 is about this theme.
The numbers in the miracle support this. 5000 are fed with 5 loaves, leaving 12 baskets of leftovers. If 5 and 12 have any symbolic significance, it's that they're very Jewish numbers. There are 5 books in the Pentateuch, the books of Moses, and 12 tribes of Israel.
By contrast, the second miracle feeds 4000 with 7 loaves, leaving 7 baskets of leftovers. 4 and 7 often have symbolic significance in the Bible. 4 frequently depicts the whole world (the "4 corners", or 4 points of the compass). 7 frequently depicts completeness and perfection.
In short, what Jesus came to bring to the 12 tribes he also gives to the whole world.