I myself had some problems with my beagle mix right around two years of age. We however had a change in our family. Both my Daughter who had been in college and my 20yr old son moved back in with us. I believe it was his being anxious to mark his spaces. If you have had a change in your family or living arrangements recently this may be the problem. My beagle was also confused as to the hierarchy of the family members until he got used to them being there.
However, marking can also mean he has reached a maturity level in which he wants to be the Alpha male. You can stop this behavior by becoming the dominant leader. He is a pack animal and must feel secure or will try to take the dominant role. Always go out a door in front of him and never let him pull you along when you walk. There are "gentle leaders" that can be used to keep him from pulling. Always talk to him as you get ready to go out telling him you are going, but make sure you exit and enter in front of him. Also, restricting him to a smaller area can also be making him feel anxious to mark the areas he has left to him. Go to http://www.howtocleanthings.com/how-to-clean-dog-u...
to find some direction on cleaning each spot as it happens.
One more thing you can do is crate him when you sleep to avoid his waking and marking in the middle of the night. I just read the previous answer from Golfgal and agree with her about giving commands. Using a firm deep voice (without yelling) to enforce your command like Bad Dog and a warmer voice to enforce Good Dog is very useful in reaffirming good and bad behaviors for your dog.