Cover and soak the beans in water for 6 to 8 hours (or overnight).
Drain and rinse the beans and place them in a large pot. Peel and cut the onion in half, leaving the root end intact. Add ½ of the onion and bay leaves to the pot with the beans and cover the beans with cold water, by 2 inches.
Bring the beans to a boil over high heat, then reduce the heat to medium low to simmer for 1 to 2 hours, or until the beans are tender but not falling apart. Remove the beans from the heat and let cool slightly.
Drain the beans and reserve the cooking liquid. Remove the onion and the bay leaves.
Return the pot to medium heat. Peel and finely chop the other half of the onion. Add the olive oil, onion, and salt to the pot. Cook for about 5 minutes, stirring occasionally, until slightly softened. Add the garlic, cumin, and chili powder, and cook for 1 minute.
Add the drained beans and ½ to 1 cup of the reserved bean cooking liquid to the pot. Bring to a simmer then remove from the heat. Use a potato masher, or an immersion blender to mash the beans to your desired consistency. (If you like a thinner consistency, stir in more of the bean cooking liquid. If you like a thicker consistency, return to the heat and cook, stirring frequently, for 3 to 5 minutes to thicken.)
Add the lime juice and season with more salt to taste.
Notes
You can swap the oil for a different fat. Homemade refried beans are traditionally made with lard. You can use this in place of the olive oil if you like. Rendered bacon fat, avocado oil, or any vegetable oil will also work well.
Finely chop the onion half that is fried with the beans so the pieces soften properly. If they're too big, they might still be a bit crunchy after cooking, making them more difficult to mash with the beans. See my tips for how to cut an onion if you need some guidance!
This makes a large amount of refried beans (about 6 cups). The recipe can easily be cut in half and cooked in a medium pot for a smaller serving size if desired.
Add toppings if you like: A sprinkle of cilantro, queso fresco, shredded Mexican blend cheese, thinly sliced jalapeno, and/or pico de gallo are all delicious additions.