Paul W. answered 04/23/19
MA Military & Diplomatic History with 10+ Years of Teaching Experience
So far as I know, there were no fortifications in Medieval Europe in which enough food could be grown to make them self-sufficient. A fundamental problem is that, in order to grow a substantial enough amount of food or, for that matter, raise a relatively sufficient number of domesticated animals, a large amount of land is needed. Fields to be tilled in order to grow grain, pasture with enough grass to provide the necessary amount of nutrition for cattle or sheep. Picture the amount of land under use that surrounded the average Medieval village, including both fields for crops and pasture for farm animals.
Thus, for a castle or other form of fortification to be self-sufficient by containing the amount of land necessary to produce its own food by growing / raising it, the walls of the castle would have to be of a tremendous length to encircle such a large area. Leaving aside the fact that this would be incredibly expensive, it would require a far bigger garrison in order to man this length of wall.
But with a greater number of men to serve as the garrison of such a castle, necessary to adequately defend a far longer length of wall, there would be that many more mouths to feed, requiring that much more food. Therefore, it's not clear if the figures could be squared; could there be enough land defended by walls to feed a large enough garrison to man the length of walls necessary to defend the necessary amount of land?