In my case, for example, I have a machine with 20GB and I would like
to know which is the best configuration if I have to use both the
replication and the sharding.
The Replication & Sharding both terms are different from each other. As Replication creates additional copies of the data and allows for automatic failover to another node.
A replica set in MongoDB is a group of mongod processes that maintain the same data set. Replica sets provide redundancy and high availability, and are the basis for all production deployments.
And sharding allows for horizontal scaling of data writes by partitioning data across multiple servers using a shard key.
As sharded cluster the set of nodes comprising a sharded MongoDB deployment. A sharded cluster consists of config servers, shards, and one or more mongos routing processes.
The briefly you can say that a MongoDB sharded cluster consists of the following components:
Each shard contains a subset of the sharded data. As of MongoDB 3.6,
shards must be deployed as a replica
The mongos acts as a query router, providing an interface between
client applications and the sharded cluster.
servers: Config servers store metadata and configuration settings
for the cluster. As of MongoDB 3.4, config servers must be deployed
as a replica set (CSRS).
For example the standard replica set deployment for production system is a three-member replica set.
In your environment you have 20GB of Data. Suppose that you are configuring & accumulate your 20GB data with 3 node replica set then sharding also require 3 node. That means for sharding total node will be require 6 nodes.
The replica set node depends on your infrastructure requirement. for replica set selection of even or odd number of members node determination you shall find here
for further your ref Replication
Difference between Sharding And Replication on MongoDB