Soak the dried navy beans in water overnight.
Drain and rinse the beans under cold water.
In a large pot, combine the beans and 4 cups of fresh water.
Bring to a boil, then reduce heat and simmer for 1 hour until beans are tender.
Preheat your oven to 300°F (150°C).
In a mixing bowl, combine brown sugar, molasses, mustard, salt, pepper, and ketchup.
Stir in the cooked beans and diced onion.
If using, add the chopped bacon to the mixture.
Transfer the bean mixture to a baking dish and cover with foil.
Bake for 1.5 to 2 hours, removing the foil for the last 30 minutes.