A Real Challenge
Mathematically it's possible: Square Cube Law.
For example:
Alpha City has:
- 50 metres of radius and it is like a square (50m x 50m). Or 100 metres each border.
- Inside it has a fertile surface of 2,500 m2 (capable of feed 250 citizens [$surface \div 10$]). $50m \times 50m$
- It has a perimetre of 200 m where they need 200 soldiers to protect it. $50m \times 4$
You can see that the city is able to support 250 citizens where 200 of them are used like soldiers, so we only have 50 to farm enough food to feed 250, pretty hard, no? $250 \div 200 = \text{1.25 citizens per soldier}$
After some time of hard effort, the Alpha city has been able to expand their walls and now they have doubled their size!
- Now it has a 100 metres radius (100m x 100m). Or 200 metres on each border.
- Inside it has a fertile surface of 10,000 m2 (capable of feeding 1,000 citizens).
- It has a perimetre of 400 m where they need 400 soldiers to protect it.
Now the city is really happy, because they are able to support 1,000 citizens and they only need 400 soldiers to protect it (they have 600 farmers to feed 1.000 persons). $1,000 \div 400 = \text{2.5 citizens/soldier}$
As you can see the ratio of citizens per soldier is bigger than before ($2.5 > 1.25$).
Each time we double the size, the perimetre would be doubled, but the surface would be quadrupled.
Using this idea you can know that with a certain number of people it is possible to make an "isolated" city surrounded by walls: the Anime Shingeki no Kyojin: Attack On Titans is an example of that, where a huge (can seem small but, it's really big) kingdom is completely self sustainable and surrounded by walls.
More Math
Soldiers
I am not sure if this is relevant for your questions, but I will post it anyway.
How many soldiers should an army have to defend a city? Well, I am not sure but I don't think a city surrounded by walls would need more than 5,000 men (in medieval age only men were in the army).
Only the 7.5% of the population (in the worst cases) were soldiers. Also I am not sure if this number (7.5%) is about men or men and women. I assume the worst scenario (7.5% of men), so a city with 5.000 soldiers should have $5.000 \div 0.075 = \text{66.666 men}$.
Ugly number so I will change it to 67,000 men. If there are at least 67,000 men there would be 67,000 women, so in the city there are 134,000 persons (this is impossible for a medieval city...). Also you have to count the older people and children. Sorry, but I am not sure how to calculate that. I believe that half of the population are children and older people: 268,000 total population.
According to Medieval Demographic Made Easy a city has 62,523 persons/km2 (38,850 per square mile) so it has $268,000 \div 62,523 = \text{4.29 } km^{2}$. I think making a square city is bad, so I'll calculate with a circle.
- $\text{Surface} = \text{4.29 } km^{2}$
- $\text{Radius} = r = \sqrt{A} \div \pi = \large \text{0.65 km}$
- $\text{Perimetre} = p = 2 \times r \times \pi = \large \text{40.88 km}$
So it has:
- $\text{Soldiers per km wall} = \text{5,000 soldiers} \div \text{40.88 km} = \large \text{122 soldiers/km}$.
Or $\text{1 soldier each 8.175 metres}$, pretty good.
Food
But we have forgotten something very important, 62,523 persons/km2 is about homes, not about the food. Luckily the same page also says that terrain is able to support 289 persons/km2 (180 per mile) AND it says "including requisite roads, villages and towns, as well as crops and pastureland" - even easier!
- $\text{Surface} = 268,000 \div 289 = \large \text{927.34 } km^{2}$
Pretty big, no? Well, you can have an inner wall of 4.29 km2 and an outside wall for crops and pasture ($\small \text{927.34} km^{2} - \text{4.29} km^{2}$) of 924.04 km2.
- $\text{Radius} = \large \text{95.67 } km^{2}$
- $\text{Perimetre} = \large \text{601.11 } km^{2}$
- $\text{Soldiers per km} = \large \text{8 } soldiers/km$
Or $\text{1 soldier each 125 metres}$, well, you have to only defend the gates.
Extra: Also your city would have:
- 589,600 animals.
Of which:
- 400,928 are fowl (chickens, geese and ducks).
- 188,672 are cows, pigs, sheep, cattle and other "meat" animals.
Now our citizens are capable of eating and sleeping, but we need to do more things.
- Food Done
- Drink, ...? Well, cities have water wells, don't they? Or at least a river or a lake... Done
- Be merry
- Mend weapons
- Make weapons
- Tend to the wounded
Jobs and Workshops
Now we can calculate the amount of jobs in the city with the same page referenced before.
Look at this table: (if anyone knows how to make a spoiler I would be so glad if he could edit this table)
$$ \left|
\begin{array}{cc|cc}
Business&SV&Business&SV\\
Shoemakers&150&Butchers&1,200\\
Furriers&250&Fishmongers&1,200\\
Maidservants&250&Beer-Sellers&1,400\\
Tailors&250&Buckle Makers&1,400\\
Barbers&350&Plasterers&1,400\\
Jewelers&400&Spice Merchants&1,400\\
Taverns/Restaurants&400&Blacksmiths&1,500\\
Old-Clothes&400&Painters&1,500\\
Pastrycooks&500&Doctors&1,700*\\
Masons&500&Roofers&1,800\\
Carpenters&550&Locksmiths&1,900\\
Weavers&600&Bathers&1,900\\
Chandlers&700&Ropemakers&1,900\\
Mercers&700&Inns&2,000\\
Coopers&700&Tanners&2,000\\
Bakers&800&Copyists&2,000\\
Watercarriers&850&Sculptors&2,000\\
Scabbardmakers&850&Rugmakers&2,000\\
Wine-Sellers&900&Harness-Makers&2,000\\
Hatmakers&950&Bleachers&2,100\\
Saddlers&1,000&Hay Merchants&2,300\\
Chicken Butchers&1,000&Cutlers&2,300\\
Pursemakers&1,100&Glovemakers&2,400\\
Woodsellers&2,400&Woodcarvers&2,400\\
Magic-Shops&2,800&Booksellers&6,300\\
Bookbinders&3,000&Illuminators&3,900\\
\end{array}
\right| $$
Each type of business is given a Support Value (SV). This is the number of people it takes to support a single business of that sort. With this you can know the amount of medics, taverns, etc in your town.
- You can see that there is a "Magic-Shop", don't pay attention...
- Also, a medic has a $*$. This is because the total amount of doctors (even without a license) is $350$.
In the case of this town it would be:
$$ \left|
\begin{array}{cc|cc}
Business&Jobs&Business&Jobs\\
Shoemakers&1,787&Butchers&223\\
Furriers&1072&Fishmongers&223\\
Maidservants&1,072&Beer-Sellers&191\\
Tailors&1,072&Buckle Makers&191\\
Barbers&766&Plasterers&191\\
Jewelers&670&Spice Merchants&191\\
Taverns/Restaurants&400&Blacksmiths&179\\
Old-Clothes&670&Painters&179\\
Pastrycooks&536&Doctors&158*\\
Masons&536&Roofers&149\\
Carpenters&487&Locksmiths&141\\
Weavers&447&Bathers&141\\
Chandlers&383&Ropemakers&141\\
Mercers&383&Inns&134\\
Coopers&383&Tanners&134\\
Bakers&335&Copyists&134\\
Watercarriers&315&Sculptors&134\\
Scabbardmakers&315&Rugmakers&134\\
Wine-Sellers&298&Harness-Makers&134\\
Hatmakers&282&Bleachers&128\\
Saddlers&268&Hay Merchants&117\\
Chicken Butchers&268&Cutlers&117\\
Pursemakers&244&Glovemakers&112\\
Woodsellers&112&Woodcarvers&112\\
Magic-Shops&96&Booksellers&43\\
Bookbinders&89&Illuminators&69\\
\end{array}
\right| $$
And for the $*$ medics they would be $766$.
So:
- We have $\text{158 licensed doctors}$. We also have $\text{766 } doctors$ counting without licensed.
So we have $\text{5000 } soldiers \div \text{158 } doctors = \text{32 } soldiers/doctors$ or even $\text{5000 } soldiers \div \text{766 } doctors = \text{7 } soldiers/doctors$.
- Tend to the wounded Ready
- We have $\text{179 } blacksmiths$.
$\text{5000 } soldiers \div \text{179 } blacksmiths= \text{28 } soldiers/blacksmith$
Well, blacksmiths would be able to supply the demand of weapons (at least without a war). In a war maybe they would have "some work", but soldier's equipment is not lost every day, so they would be able to supply the demand in time (you can have spares).
- Mend weapons Done (remelt broken weapons)
- Make weapons Done if they have an iron mine or copper + tin mine. They don't even need a mine at all. 5.000 soldiers won't have more than 25.000 kg of metal, right? In iron you can save it in 3.14 m3 (you can store it).
- As you can see they have several locals (400 restaurants and taverns) so:
- Be merry Done?
The wall
Oh, I forgot something, the wall. A normal wall is about 2.5m x 10m. Also a good wall is made out of stone, so: (I am calculating that the wall is filled inside. It's false, so you can even use this materials to build a thicker wall.)
- If you choose the first wall (without farms) it would take 1.022.000 m3 of stone.
- If you choose the second wall it would take 15.027.750 m3 of stone.
I think it would take several years (for the first, maybe one generation for the second...) of working to make the wall. Luckily you have 67.000 men (worker force)...
Resources
A self sustainable city needs all kinds of ores, metals and plant to survive alone. Luckily our city is very large, so it has a lot of terrain to find these resources, or at least to make huge stockpiles for war times.
A self-sustainable city needs all kinds of ores to be able to survive alone. With my knowledge and this question that I asked I get to the conclusion that your city needs:
- Wood: wood is used very often in that age. It's a cheap and easy construction material (which can replace the stones of walls) and also it's used like charcoal. Sadly, ores are "almost" endless in a medieval age, but trees aren't, the city would need orchards and manual forestation (this, like ores, would take more surface, so you would need to expand your city).
- Land suitable for agriculture and pasture: obviously you need a lot of different crops and animals.
- Stone: "advanced" building material, very strong.
- Iron / Bronze (Copper + Tin): hard metals used to build swords, armours and a lot more things.
- Clay and lime: not needed for an army, but it's very common in the everyday items of the medieval age.
- Antimony + lead: used in everyday life.
- Salt: food conservation.
- Coal: useful, but can be replaced with charcoal.
- Silver / Gold: for coining. You need a currency (you can also use copper, tin, aluminium, antimony, iron, etc).
I hope this could help and sorry if I went through the branches.