I keep finding on the net that in medieval times, peasants and nobles owed 40 days a year of military service to their ruler.
But that doesn't make any sense, how could anyone have accomplished anything worthwhile in only 40 days?
My question is if it was only 40 days and also (if it is as such), how did rulers keep their subjects in their armies for longer periods of time.
Did they pay them to remain? Did they force them to stay? And did some of them volunteer to stay?
The question is regarding High Middle Ages up to the end of the Middle Ages. Any answer will do.
I will attempt to answer this inquiry from my perspective as an amateur historian with interest in the low countries during the middle ages. In this particular context, I will limit my response to the high and late middle ages as there's simply a greater number of sources from that period that can help us determine how the levy functioned in those times in comparison to the (relative) small number of sources on the same matter in the early middle ages, at least where it concerns continental Europe. I'm not an expert on the Anglo-Saxons, but I believe we do have some considerable sources on the function and composition of the early middle age fyrd. Where it concerns the levy in the aforementioned high and late middle ages, there are a great number of parallels between the various European territories, as such I will extrapolate (I believe that is the correct term?) what we know about the levy in the low countries to the the levy of, for example, the kingdom of England, as well as the rest of France and the Holy Roman Empire (which respectively Flanders and the other locales comprising the low countries were a part of). If there are particular exceptions to this, I will try to be clear about it.
All the locales I mentioned above had an approximate of the levy system in place. And indeed, it seems to have been the rule that a levy (both knighthood and commoners) was raised for a period of 40 days. While this seems to be a small window to achieve strategic and tactical goals (more about achieving military successes later), we have to put a single levy in the context of a whole chain of levies, which was the true purpose of the levy system: if a campaign lasted for more than 40 days, levies were raised one after the other in a rotational pattern, in order to allow one levy contingent to replace a previous one and as such not strain the demographic and associated economy. Levies were not simply a matter of raising every man able to fight for a period of 40 days, but rather a system that allowed territories to raise forces according to predetermined parameters. Of course, it can be difficult in the middle of military operations to cleanly cut your business and turn your men home as soon as 40 days have passed, at which point the levy had to be reimbursed and fed for every day they served additionally. More about pay and food later.
Parameters around the levy were gender, age, and the intensity of the levy. Only men were seen as combatants, and these men had to be men, not boys, albeit while the age was officially set (between the age of 20 and 60 in many parts of the Holy Roman Empire) this does not seem to be enforced to the letter. The intensity of the levy was also important. Levies could be raised single, double, triple or quadruple (this had different terminology in different locales). Single levy raises 1 man, double raises 1.5 men, triple raises 2, quadruple raises 3 (or 2.5, depending on the source) men. For example, if double levy was called in a town or city determined to raise 600 men for a normal levy (a normal amount for a city with roughly 8000 inhabitants), they had to provide 900 men. Logically, the intensity seems to have been dependent on the military goals as well as the demographic and economic situation.
To continue on the subject of payment and rationing. During the high middle ages it was custom for knighthood and commoners (and expected of them) to serve their levy period for free as well as (officially) to arrange for their own food. However, we have to see the latter as a way of limiting the juridical responsibility of the lord, as in practice it was more often the case that the food and necessary logistics were arranged for by the lord, who then would supply their men with rationing for a reasonable price. This is a whole different can of worms, but in general medieval commanders could be quite competent in matters of logistics and some of the most important sources we have on military campaigns are receipts of the large scale purchase of foodstuffs and transport in urban centres. The image of roving bands of men plundering the countryside has to be seen primarily in the context of damaging the opponent's logistical and economical infrastructure and not as the primary means of obtaining sustenance (exceptions notwithstanding, such as when an army was stuck 'behind enemy lines' with compromised logistics). The conduct surrounding payment changed (in general; the conduct could differ from lord to lord) in the late middle ages, and from the early 14th century most of Europe paid the levy even during the initial 40 day period. Some territories, such as the county of Holland, were an exception to this, where most men were still expected to meet the 40 day demands solely on grounds of loyalty rather than reward.
Concerning the use of the levy to attain military goals, one of the most inhibiting factors was that achieving tactical surprise was virtually impossible if the opponent paid any form of attention. Reason for this is that the mobilization of the levy was a slow and cumbersome affair where the local approximates of bailiffs and sheriffs had to call and gather the levies at certain predetermined mustering sites where a general inspection took place in order to establish whether or not the armament was adequate. The time period between calling the levy and mustering was set at 14 days in the relatively small territory of the county of Holland; a period that was at least equal in larger more centralized territories. As such troop concentrations and movement were evident before a campaign even began. While this seems horribly inefficient, it's less so if we consider that in the case of a foreign invasion most locales had a version of the home guard (Dutch landweer, German landwehr) which was an all-hands-on-deck style levy where every man able to hold a weapon was expected to do so for an indefinite time until the threat was thwarted (or there was no one left).
I hope that answers some of your questions. If you have more on the matter, please ask. Additionally, I have written about the levy system in the county of Holland in particular before, and this might give some more insight.
Sources
Mainly Jansen & Hoppenbrouwers (1977) with their congressional dissertation still being the foremost academic literature on the levy in the Netherlands, used among others in De Graaf (2004) whose book Oorlog om Holland 1000-1375 (War for Holland 1000-1375) places this levy system in a much needed operational context.