One small room can serve both purposes if you buy the right furniture.
Start with a Murphy bed. It’s a bed with one edge attached to the wall so it hangs from the wall while it’s in use, and you can swing it up against the wall when you don’t have visitors.
Place a desk on the opposite wall. With the Murphy bed suspended flat against the wall, you’ll have plenty of room to move around in a desk chair while you’re working. When the bed is pulled down for company, there won’t be much room, but you probably won’t want to work in that space then anyway.