The Gemara in Chullin (111b) brings down a dispute about a fish that had gotten the taste of meat from a pot and then one wants to eat the fish with dairy. Rav says that since the fish was cooked in a meat pot the fish may not be eaten with dairy because there is the taste of meat in the fish. Eating it with dairy is like eating milk and meat together. Shmuel disagrees, and says that the fish may be eaten with dairy, despite having been cooked in a meat pot, because the taste of meat that is in the fish is only secondhand (which we will refer to as nat bar nat). This means, according to Shmuel, since the taste of meat first went into the pot and only then went from the pot to the fish, the taste of the meat is weaker and is permitted with dairy.
Nat bar nat stands for noten taam bar noten taam. This translates as taste which comes from taste (as opposed to taste which came from actual food). When one cooks a piece of meat in a pot, the taste of the meat that leaves the meat itself and gets transferred into the pot is the first level of taste – taam rishon. When one subsequently cooks pareve food in the pot, the taste of the meat leaves the walls of the pot and goes into the pareve food. This is already step two for the taste, so it is called taam sheini, and is weaker than the original taste of meat. The taam sheini is what we refer to as nat bar nat.
There are three shitos in the rishonim explaining how the fish acquired the taste of the meat, and consequently when nat bar nat is permitted:
According to Rashi the fish would be permitted if it were merely placed in a meat pot while the fish was hot, but if the fish had been cooked in the meat pot, then it would not be permitted with dairy. The reason is that if the fish were merely placed in the pot while hot then it only absorbed meat into the outer kelipa of the fish and the taste of meat is weak so we permit the fish with dairy. But, if it was cooked in the pot, then it would have a taste of meat throughout the fish and we would not be lenient to eat the fish with dairy.
The Rosh explains that the Gemara is referring to a fish that was actually cooked in a meat pot, and it is permitted to eat that fish with dairy. The Rosh points out from the Sefer Hatrumot that the fish is only permitted if there were a total of three steps that the taste took to arrive in the fish, meaning from the meat to the pot, from the pot into the water that the fish is cooking in, and from the water to the fish itself. But, if the fish was cooked in the pot without any liquid (tzli kadur), the fish may not be eaten with dairy, as the taste of meat only moved through two steps to arrive in the fish.
The Rashba and the Ran explain that no matter how the fish absorbed the taste of meat from the pot, it would be permitted to eat the fish with dairy. It does not make a difference if the fish was cooked or roasted in the pot.
We permit the taam sheini of meat with milk (like Shmuel in the Gemara) only when the taam sheini existed before it mixed with milk. Otherwise it would be forbidden. Meaning, if the taste of meat left the pot and went into a pareve food and only then one mixed the pareve food with milk, the meat taste already had the status of taam sheini before being introduced to the milk. Therefore it is permitted with milk. However, if one cooked actual dairy food in a pot that previously had meat cooked in it, the taste of the meat goes directly into dairy and never has the chance to acquire the status of taam sheini. This is as if taam rishon of meat went directly into milk and is the standard prohibition of meat and milk which is biblically prohibited. (עיין ש”ך יו”ד צה ס”ק ה)
The Ran (מובא בד”ך יו”ד צד ס”ק כב) says that the rule of taam sheini is only that it cannot create a new instance of prohibition, but if there was something which was previously forbidden when it was taam rishon, the taam sheini of that food is forbidden. This means that if one cooked non-kosher food in a pot, and then cooked kosher food in that pot, even though the taste of non-kosher food that got absorbed into the kosher food is taam sheini, it is still forbidden to eat it. Only when the taam sheini was in existence as permitted food is it considered a weakened taste that no longer has the power to create new prohibitions. This means that taam sheini of meat (or milk) cannot create a new prohibition of basar b’chalav, even when mixing with milk (or meat).
The Beis Yosef (בית יוסף יו”ד צה) discusses a dispute about nat bar nat. Rabbeinu Yerucham’s opinion is that nat bar nat is only permitted after the fact, but one may not initially cook something in a meat pot with the intention of eating it with dairy. However, the Beis Yosef argues that there is no reason to differentiate between before and after the fact. It would be permitted either way. The Shulchan Aruch (יו”ד צה:א-ב) rules that if fish was cooked in a meat pot it may be eaten together with dairy, whether it was cooked or roasted (like the Ran), but that it is only permitted after the fact. One may not initially cook the fish with the intention of eating it with dairy. The Kaf Hachaim adds that if the pot was not a ben yomo, it would be permitted to cook the fish in the meat pot, even initially, with intention to eat it with dairy.
The Rama (יו”ד צה:ב) differs with the Shulchan Aruch. He rules that only fish which was placed, while hot, in a meat pot can be eaten with dairy, but not if the fish was cooked in the meat pot (like Rashi). The Rama though is lenient if the fish was cooked in a meat pot and accidentally mixed with dairy. He rules that one may rely on the rishonim that assert it is permitted even if it was cooked and one can eat it after the fact. The Shach (שם ס”ק ו) adds, the rule of the Rama that allows hot food, that was placed in a meat pot to be eaten with dairy, is only applicable if the pot was cold. If the pot and the food were both hot, then it would be forbidden because it is considered as if the food was roasted in the meat pot. The Rama continues and says that nat bar nat is only true concerning foods that are not very sharp. If, however, one cooked a sharp food in a meat pot, the sharpness makes the flavor that gets pulled out strong and it is as if it absorbed flavor directly from the meat.
The Rama writes about two more permissible actions once a food had been cooked in a meat pot. The first is to place it on a dairy dish, even while the food is hot. One should be careful, however, not to pour the food directly from the meat pot onto the dairy plate (רמ”א יו”ד צה:ג, וע”ע ש”ך שם ס”ק ה שהקיל בדיעבד). The second is if the meat pot was not a ben yomo, it would be permitted to mix the food directly into dairy.
Rav Moshe Feinstein (יו”ד ח”ב סי’ י אות ב) writes that even according to the Rama, one may initially place hot food on a meat plate with intention to place it on a dairy plate after. In Sefer Hilchos Basar B’chalav (ח:כ) it is written that it is permitted to cook pareve food in a meat pot with the intention of mixing it with pareve food cooked in a dairy pot.
In summary; the Shulchan Aruch holds that it is initially permitted to take food that had already been cooked in a meat pot and mix it with dairy, but not to initially cook the food in a meat pot with the intention of mixing it with dairy afterwards. The Rama holds that one may not even mix the foods after they had been cooked, but if the food was already mixed, then it is permitted to eat it. If the meat pot was not a ben yomo then one may initially mix the foods. One may take food that had already been cooked in a meat pot and place it on a dairy dish, even while the food is hot. All the above is only true concerning milk and meat. However, concerning a pot that had forbidden food cooked in it, there is no halacha of nat bar nat, rather the taste is always forbidden. If one cooked a sharp food in a pot it is taam rishon, and is not considered nat bar nat.