The wallet software you use will get suggestions for the price to pay for the fee for you. It's a best guess and nimrally based either on the past or the present.
When you send a transaction it gets sent to the "mempool" which is a pool of all the transactions nodes broadcast. This is sorted by fee by miners and the top 20mb are normally in for consideration by most nodes (I *think*) it's possible to bump the fee after the transaction is sent if you select "replace by fee" (rbf) in your wallet settings.
Past analysis by clients takes into account intervals of blocks in th past (normally ranging from 144 blocks - a day - to 2048 blocks - about 2 weeks). Which can determine if fees are going up and the best fee for a confirmation within a certain timeframe.
And yes it's possible the fee can be too low to be mined and it's also possible for a fee to be too low to be broadcast across the network.