One of my sister-in-laws breastfed her oldest till he was 4. I think it was mainly because he was such a sickly baby and had so many problems. So like @justusthree said, it depends on the situation. I plan on breastfeeding her till 3 or 4 however, when she's 2 I'll just pump and give it to her in a bottle and not hook her to my boobs. Breast milk helps keep their immune system up and gives them nutritional benefits that they normally would not get in most Foods nowadays. So as long as I'm able to pump it out and put it in a bottle or a cup even when she gets older I'll probably give it to my daughter as long as possible. But when it comes to her latching onto my breasts I will probably wean her off around 2 years old.
I think it really depends on your situation. Some babies actually need it longer because they're allergic to so much and some babies need it for comfort.
I think letting them self wean is good, and always encourage it when they start to. But if it gets to a point when you're ready to stop, I would start the weaning process and let them go with it.
I feel like longest should be 2. After that I agree with @kambam they should be drinking from a cup.
K thanks my husband said to just let him wean himself but I seen on the internet some still breastfeeding at six years old. Probably two or three is long enough