Making frijoles refritos from scratch is a test more of patience than of skill. Though they take much longer to prepare, homemade frijoles refritos are infinitely superior to the canned kind. The details of preparation vary according to region, but the basic recipe remains the same: cook a pot of beans until they're soupy, and then fry those beans in fat until they thicken.
Begin by soaking the beans overnight; then drain them, cover them with water again, and stew them until they are tender. When the beans have been cooked to a uniform texture (about one and a half to two and half hours; this is part that requires patience), in a separate pot sauté a chopped onion in either lard, bacon drippings, or, for vegetarians, vegetable oil. Stir your beans into the onion and season them with spices like cumin and chili powder, mashing the mixture gently with your spoon until it combines and has reduced to a thick consistency.
In Mexico, cooks flavor frijoles refritos with everything from manteca (pork lard) to epazote (an anise-flavored herb) to beer (no explanation required). Each addition to the base creates a different layer of taste in this protein-rich dish, but the essential flavor is that of the beans, so it's crucial to choose the right variety. Cooks from northern Mexico frequently use pink or pinto beans, while southern Mexican chefs prefer smaller, firmer black beans. Any of those, along with a whole host of others—flor de mayo, bayo, piruano—will yield a good batch.
One mistake that many cooks make is to allow the liquid to cook down fast, rendering the beans hard on the inside while their outsides burn. This can be prevented easily if you keep a cup of cold water on hand to add to the beans as necessary, since cold water slows the cooking process. Different beans require different cooking times, black beans taking the longest. Fresh frijoles refritos store well in the freezer for months, though, so your patience will truly pay off.